简体   繁体   English

使用 Selenium Chromedriver 和 python 我如何点击这个元素?

[英]Using Selenium Chromedriver with python how do i click this element?

I am want to be able to click this element in the Yandex account sign up page.我希望能够在 Yandex 帐户注册页面中单击此元素。

I am using Selenium Chromedriver with python.我正在使用 Selenium Chromedriver 和 python。

https://passport.yandex.com/registration/ https://passport.yandex.com/registration/

我想自动点击这个元素。

I have tried this code我试过这段代码

element = self.driver.find_element_by_class_name("toggle-link.link_has-no-phone").click()
        webdriver.ActionChains(self.driver).move_to_element(element).click(element).perform()

but I get ElementClickInterceptedException.但我得到 ElementClickInterceptedException。

There's a element.click().perform()有一个element.click().perform()

and you can also send a Return key to the element您还可以向元素发送一个Return

from selenium.webdriver.common.keys import Keys


element = ... # get your element
element.send_keys(Keys.RETURN) # or send a left mouse click

It looks like the way you're finding the element is wrong, there are two classes for that element and you have tried to specify both -> find_element_by_class_name only takes one class attribute value.看起来您查找元素的方式是错误的,该元素有两个类,并且您尝试同时指定两者 -> find_element_by_class_name 仅采用一个 class 属性值。

So, this should work for you所以,这应该适合你

driver.find_element_by_class_name('link_has-no-phone').click()

Not sure why you are using ActionChains here while you can simply click on the mentioned link.不知道你为什么在这里使用ActionChains ,而你可以简单地点击上面提到的链接。

Simplified code简化代码

self.driver.find_element_by_class_name("toggle-link.link_has-no-phone").click() 

OR或者

element = self.driver.find_element_by_class_name("toggle-link.link_has-no-phone")
element.click()

OR或者

driver.find_element_by_css_selector('.toggle-link.link_has-no-phone').click()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法使用 Selenium、Python 和 ChromeDriver 访问元素 - Unable to access the element using Selenium , Python and ChromeDriver 如何在 Python 中使用 Selenium chromedriver 单击按钮 - How to click a button with Selenium chromedriver in Python 如何使用Python正确单击Selenium中的元素? - How do I properly click an element in Selenium with Python? 如何让 Selenium Python 单击按钮元素? - How do I make Selenium Python click on a button element? 如何使用 Google Chrome 而不是 Chromedriver Python Selenium - How do I use Google Chrome instead of Chromedriver Python Selenium 如何更改选择器以使网站显示登录而不是使用 selenium python 和 chromedriver 进行注册? - How do I change the selector so that the website shows login instead of signup using selenium python and chromedriver? 如何使用 Selenium ChromeDriver 执行右键单击? - How to perform right click using Selenium ChromeDriver? 如何使用 selenium 和 beautifulsoup 单击元素? - How do I click an element using selenium and beautifulsoup? 将chromedriver与Selenium结合使用时,如何更正超时错误? - While using the chromedriver with Selenium, how do I correct a timeout error? 如何使用chromedriver使用硒在网页中找到这些特定元素? - How do I find these particular elements in a webpage, with selenium using chromedriver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM