Home > Back-end >  selenium python cant click button (should be quick)
selenium python cant click button (should be quick)

Time:07-23

what in trying to click

<div  onclick="registerAcc()">Register</div>

if you visit krunker.io and inspect and then just ctrl f "register" you should find it

here is my code

driver.find_element(By.CLASS_NAME,"Register").click()

and the error is "no such element"

CodePudding user response:

i have tried to open krunker.io, and found out the register not like what you discribed. as u discribed in your questions, the right code is:

driver.find_element(By.CLASS_NAME,"accBtn button buttonP").click()

compare with my code and your code, you will find out that the class name is just behind "div --no-sandbox") # chrome_options.add_argument("--headless") webdriver_service = Service("chromedriver/chromedriver") ## path to where you saved chromedriver binary browser = webdriver.Chrome(service=webdriver_service, options=chrome_options) url = 'https://krunker.io' browser.get(url) WebDriverWait(browser, 200000).until(EC.element_to_be_clickable((By.ID, "onetrust-accept-btn-handler"))).click() print('Accepted terms') WebDriverWait(browser, 200000).until(EC.element_to_be_clickable((By.XPATH, "// div[contains(text(), 'Login or Register')]"))).click() print('clicked login/register') WebDriverWait(browser, 200000).until(EC.element_to_be_clickable((By.CLASS_NAME,"buttonP"))).click() print('clicked Register button')

  • Related