0
<div id="start" class="btn btn-huge btn-success"><i class="fas fa-power-off"></i> Start</div>

This is the HTML code line in the view source of a website. It is the code line for a start button that is on the website. I am using selenium with python and i want to locate this start button and click it. I have tried to use the following:

browser.find_element_by_css_selector("div.btn btn-huge btn-success").click()
browser.find_element_by_id("start").click()

and the .find_element_by_xpath() method too.. but none of them seem to work. I dont know if the code is able to locate that start button or not, but it is not clicking it so i am assuming that it is not locating it.. please tell me how i should fix this.. :) this is my complete code:

import undetected_chromedriver as uc
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
import time

browser = uc.Chrome()
browser.get('https://aternos.org/server/devialcraft')
browser.refresh()
time.sleep(1)
username = browser.find_element_by_id("user")
username.clear()
username.send_keys("Not_Breadbutter")

time.sleep(2)
password = browser.find_element_by_id("password")
password.clear()
password.send_keys("my_password")

time.sleep(2)
browser.find_element_by_id("login").click()


browser.refresh()

browser.refresh()
browser.find_element_by_css_selector("div.server-name").click()
#This is the line where i am locating that button:
time.sleep(1)
browser.find_element_by_css_selector("div.btn btn-huge btn-success").click()
time.sleep(9)
browser.quit()
  • where you get stuck? are you using implicity_time to wait element presented? probably refresh before get element without wait cause your problem, your python code run faster website load – Wonka Oct 28 '21 at 08:30

1 Answers1

0

I do not have the right credentials to check the HTMLDOM.

But your this line of code :

browser.find_element_by_css_selector("div.btn btn-huge btn-success").click()

is wrong cause CSS is wrongly used.

Please try :

browser.find_element_by_css_selector("div.btn.btn-huge.btn-success").click()

The reason behind this is, it is a combination of multiple class, so in Selenium we use . to combine these classes.

PS : Please check in the dev tools (Google chrome) if we have unique entry in HTML DOM or not.

Steps to check:

Press F12 in Chrome -> go to element section -> do a CTRL + F -> then paste the css and see, if your desired element is getting highlighted with 1/1 matching node.

Diagnosis :

  1. Check if it is in an iframe.

  2. Check if it is in shadow root.

  3. Have you been redirected to a new tab or windows?

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • Sorry but it did not solve my problem :( (that is why i didnt reply to this solution; reffering to ur comment on my other question) – Bread_butter Oct 28 '21 at 13:01
  • then why are you using my solution here https://stackoverflow.com/questions/69752064/why-is-selenium-code-not-responding-after-the-first-few-steps – cruisepandey Oct 28 '21 at 13:02
  • I just replaced that line of code with what u suggested but i dont know yet if that would work or not becuase the code before it is not getting executed in the first place. – Bread_butter Oct 28 '21 at 13:15