ultrafunkamsterdam / undetected-chromedriver

Custom Selenium Chromedriver | Zero-Config | Passes ALL bot mitigation systems (like Distil / Imperva/ Datadadome / CloudFlare IUAM)
https://github.com/UltrafunkAmsterdam/undetected-chromedriver
GNU General Public License v3.0
9.47k stars 1.13k forks source link

WebDriverWait returning a Dictionary? #324

Open athenawisdoms opened 2 years ago

athenawisdoms commented 2 years ago
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import undetected_chromedriver.v2 as uc

options = ...
CHROME_DRIVER_PATH = '/usr/bin/chromedriver'
driver = uc.Chrome(executable_path=CHROME_DRIVER_PATH, options=options, headless=False)
driver.get(TARGET_URL)

try:
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.ID, 'add-to-cart-button'))
    )
    print("element:", element, type(element)
    element.click()
except Exception as e:
    print("Exception:", e)

gives the output

element: {'ELEMENT': '0.46737692102706485-2'} <class 'dict'>

and error

Exception: 'dict' object has no attribute 'click'

Same error if I try

element = driver.find_element(By.ID, "add-to-cart-button")
element.click()

or

element = driver.find_element_by_id("add-to-cart-button")
element.click()

I don't think element should be a Dictionary, did I go wrong somewhere?

frederikme commented 2 years ago

Could you try running the following?

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import undetected_chromedriver.v2 as uc

options = ...
CHROME_DRIVER_PATH = '/usr/bin/chromedriver'
driver = uc.Chrome(executable_path=CHROME_DRIVER_PATH, options=options, headless=False)
driver.get(TARGET_URL)

try:
    xpath = '//*[@id="add-to-cart-button"]'
    WebDriverWait(driver, 10).until(EC.presence_of_element_located(
                (By.XPATH, xpath)))

    element = driver.find_element(By.XPATH, xpath)
    element.click()
except Exception as e:
    print("Exception:", e)