[英]How do I locate and click this start button using selenium and python?
<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.这是网站视图源代码中的 HTML 代码行。 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.
我在 python 中使用 selenium,我想找到这个开始按钮并单击它。 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.和
.find_element_by_xpath()
方法也是......但它们似乎都不起作用。 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()
I do not have the right credentials to check the HTMLDOM
.我没有检查
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.是错误的,因为 CSS 被错误地使用。
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 .
这背后的原因是,它是多个类的组合,所以在 Selenium 中我们使用
.
to combine these classes.组合这些类。
PS : Please check in the dev tools
(Google chrome) if we have unique entry in HTML DOM
or not. PS:如果我们在
HTML DOM
是否有唯一条目,请检查dev tools
(谷歌浏览器)。
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. Press F12 in Chrome
-> 转到element
部分 -> 执行CTRL + F
-> 然后粘贴css
并查看您想要的element
是否被1/1
匹配节点突出显示。
Diagnosis :诊断 :
Check if it is in an iframe.检查它是否在 iframe 中。
Check if it is in shadow root.检查它是否在影子根中。
Have you been redirected to a new tab or windows?您是否被重定向到新选项卡或窗口?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.