[英]How to click on the element with Selenium Python
I'm trying to click a the element with text as I don't have the telephone on this website . 我试图单击带有文本的元素,因为该网站上没有电话 。
So I find the element with inspect. 因此,我发现与检查元素。 here is the element in html:
这是html中的元素:
<span class="toggle-link link_has-no-phone" role="button">I don't have a telephone number</span>
In my nonfunctional code i wrote this: 在我的非功能性代码中,我这样写:
r = driver.find_element_by_xpath("//*[@id='root']/div/div[2]/div/main/div/div/div/form/div[3]/div/div[2]/div/span")
r.click
The button is never clicked and nothing happens i get no error and i can't click it any help would be appreciated. 该按钮永远不会被单击,并且什么也不会发生,我不会收到任何错误,并且我无法单击它,因此不胜感激。
You can use css selector below to get span: 您可以使用下面的CSS选择器来获取跨度:
r = driver.find_element_by_css_selector(".link_has-no-phone")
r.click()
r = driver.find_element_by_xpath("//*[@id='root']/div/div[2]/div/main/div/div/div/form/div[3]/div/div[2]/div/span")
r.click()
You just forgot the parenthesis 你只是忘了括号
To click on the element with text as I don't have a telephone number you can use either of the Locator Strategies : 要在没有电话号码的情况下单击带有文本的元素,可以使用“ 定位器策略”之一 :
css_selector
: css_selector
:
driver.find_element_by_css_selector("span.toggle-link.link_has-no-phone").click()
xpath
: xpath
:
driver.find_element_by_xpath("//span[@class='toggle-link link_has-no-phone']").click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.