kaliiiiiiiiii / Selenium-Driverless

undetected Selenium without usage of chromedriver
https://kaliiiiiiiiii.github.io/Selenium-Driverless/
Other
412 stars 52 forks source link

switch_to.target: 'str' object has no attribute 'to_json #9

Closed ruslanx3m closed 11 months ago

ruslanx3m commented 11 months ago

Switching to iframe 62F39492BC29F01259DA297E862DA9DA 'str' object has no attribute 'to_json' Error while switching to iframe

    targets = driver.targets

    print("Targets:", targets)

    target = None

    iframe_url_pattern = re.compile(r"turnstile")

    for target in targets:
        if target["type"] == "iframe":
            if iframe_url_pattern.search(target["url"]):
                target = target
                print(target["url"])
                break

    if not target:
        print("No iframe found")
        return False

    print("Switching to iframe", target["targetId"])

    try:
        driver.switch_to.target(target["targetId"])
    except Exception as e:
        print(e)
        print("Error while switching to iframe")
        return False

    print("Switched to iframe")
kaliiiiiiiiii commented 11 months ago

Yep, thanks, I'll have a look at it

kaliiiiiiiiii commented 11 months ago

Should now be resolved with selenium-driverless>=1.2.5

example script:

import time
from selenium_driverless.sync import webdriver

options = webdriver.ChromeOptions()
with webdriver.Chrome(options=options) as driver:

    driver.get("https://www.w3schools.com/html/html_iframe.asp")

    iframe = None
    while not iframe:
        for target in driver.targets:
            if target["type"] == "iframe":
                if True:  # filter out iframe here
                    iframe = target
                    break
        time.sleep(0.1)

    driver.switch_to.target(target["targetId"])
    print(driver.title)

@ruslanx3m if this resolves your issue, please close it.

ruslanx3m commented 11 months ago

AttributeError: 'str' object has no attribute 'to_json'

kaliiiiiiiiii commented 11 months ago

AttributeError: 'str' object has no attribute 'to_json'

?

ruslanx3m commented 11 months ago

Hi, updated the Selenium-Driverless and now is working! thank you!

ruslanx3m commented 11 months ago

Hi, updated the Selenium-Driverless and now is working! thank you!