【问题标题】:Why I can't send click in selenium python to an element?为什么我不能将 selenium python 中的点击发送到元素?
【发布时间】:2018-04-12 04:53:09
【问题描述】:

我正在尝试将点击发送到一个元素,但它不起作用。

我在 python 3.6 中使用 selenium 并且元素是

 <a class="_m3m1c _1s3cd" href="#" role="button">Load more comments</a>

我的代码:

post = browser.find_element_by_class_name('_ebcx9')
comment_list = post.find_element_by_tag_name('ul')
comments = comment_list.find_elements_by_tag_name('li')

我试过了

ActionChains(browser).move_to_element_with_offset(comments[1], 5, 5).click().perform

甚至

ActionChains(browser).click(comments[1].find_element_by_tag_name('a')).perform()

我做错了什么?

请帮帮我。

【问题讨论】:

    标签: css python-3.x selenium selenium-webdriver xpath


    【解决方案1】:

    根据您提供的将click() 发送到元素的 HTML,您可以使用以下任一代码行:

    • 链接文本

      driver.find_element_by_link_text("Load more comments").click()
      
    • XPATH

      driver.find_element_by_xpath("//a[@role='button' and contains(.,'Load more comments')]").click()
      

    【讨论】:

      猜你喜欢
      • 2013-05-06
      • 1970-01-01
      • 2021-03-22
      • 2021-05-17
      • 1970-01-01
      • 2016-01-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多