Home > OS >  selenium: find element not working (should be quick, so plz help)
selenium: find element not working (should be quick, so plz help)

Time:07-21

trying to click on "i accept" button but doesn't work

import time
import undetected_chromedriver as uc
import selenium
def login_Undetected():
    driver = uc.Chrome()
    driver.get('https://krunker.io/')
    time.sleep(4)
    driver.find_element_by_css_selector("input[id*=onetrust-accept-btn-handler]").click()
    time.sleep(2)
   
login_Undetected() 

gives error:

driver.find_element_by_css_selector("input[id*=onetrust-accept-btn-handler]").click()

File "C:\Users\hi\AppData\Roaming\Python\Python37\site-packages\undetected_chromedriver_init_.py", line 433, in getattribute return super().getattribute(item) AttributeError: 'Chrome' object has no attribute 'find_element_by_css_selector'

CodePudding user response:

Use find_element instead.

find_element_by_css_selector doesn't exist anymore.

from selenium.webdriver.common.by import By
driver.find_element(By.CSS_SELECTOR, 'input[id*=onetrust-accept-btn-handler]')
  • Related