0

I'm trying to click

<div class="accBtn button buttonP" 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"

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

0

This is a very content-heavy website, so a way to interact with it would be:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


chrome_options = Options()
chrome_options.add_argument("--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')
Barry the Platipus
  • 9,594
  • 2
  • 6
  • 30
0

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 class="

besides, you will need to find the right html codes position before the code works

yaqin2015
  • 36
  • 3
0

The Krunker website uses AJAX calls.


Solution

To click on the element Register you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following locator strategies:

driver.execute("get", {'url': 'https://krunker.io/'})
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@id='onetrust-accept-btn-handler']"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@id='signedOutHeaderBar' and contains(., 'Login or Register')]"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@class='accBtn button buttonP' and text()='Register']"))).click()

Note: You have to add the following imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352