【问题标题】:Using Selenium Chromedriver with python how do i click this element?在 python 中使用 Selenium Chromedriver 我如何单击此元素?
【发布时间】:2020-05-24 23:17:12
【问题描述】:

我希望能够在 Yandex 帐户注册页面中单击此元素。

我在 python 中使用 Selenium Chromedriver。

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

我试过这段代码

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()

但我得到 ElementClickInterceptedException。

【问题讨论】:

  • 在代码中选择它之后,你会有类似 .click() 之类的东西(我不记得确切没有使用硒一年),你也可以使用ActionChains这是人性化的方法,用于躲避机器人检查员和这类东西
  • 谢谢,我已经尝试过您建议的代码,但很遗憾没有奏效。

标签: python selenium selenium-chromedriver bots


【解决方案1】:

有一个element.click().perform()

您还可以向元素发送Return

from selenium.webdriver.common.keys import Keys


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

【讨论】:

    【解决方案2】:

    看起来您查找元素的方式是错误的,该元素有两个类,并且您尝试同时指定两者 -> find_element_by_class_name 仅采用一个类属性值。

    所以,这应该适合你

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

    【讨论】:

      【解决方案3】:

      不确定您为什么在此处使用ActionChains,而您只需单击提到的链接即可。

      简化代码

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

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

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

      【讨论】:

      • 这些都不起作用。在发布问题之前,我已经尝试过这些。我收到“ElementClickInterceptedException”,这意味着 Yandex 知道我正在使用自动化软件尝试单击该特定元素,然后阻止我这样做。
      • 可能有问题。您应该在您的问题中添加完整的代码,因为我已经尝试过使用上述代码并且它对我来说没有任何麻烦。
      猜你喜欢
      • 2021-03-12
      • 2022-12-04
      • 2016-05-28
      • 1970-01-01
      • 2021-03-31
      • 1970-01-01
      • 2021-12-09
      • 2017-11-23
      相关资源
      最近更新 更多