为什么我无法将 selenium python 中的点击发送到元素? [英] Why I can't send click in selenium python to an element?
本文介绍了为什么我无法将 selenium python 中的点击发送到元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将点击发送到一个元素,但没有奏效.
I am trying to send click to an element but it didn't work.
我在 python 3.6 中使用 selenium元素是
I'm using selenium in python 3.6 and the element is
<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()
我做错了什么?
请帮帮我.
推荐答案
根据您提供的将 click()
发送到元素的 HTML,您可以使用以下任一代码行:
As per the HTML you have provided to send click()
to the element you can use either of the following line of code :
链接文本:
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()
这篇关于为什么我无法将 selenium python 中的点击发送到元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文