python selenium 无法点击标签

标签 python selenium

我正在尝试单击下面显示的名为“Segment Metrix 2.0 Consumer Target Profile report”的按钮

enter image description here

我找到了相应的 HTML,如下所示。

enter image description here

我尝试编写如下代码:

elem = driver.find_elements_by_xpath("//*[contains(text(), 'Segment Metrix 2.0 Consumer Target Profile report ')]")
print (elem)

它给了我:

[<selenium.webdriver.remote.webelement.WebElement (session="daf65f4e5ed0485027d04eed8db8aca7", element="0.8079987809618281-1")>]

但是我不能通过添加 elem[0].click() 来点击它,它会抛出一个“元素不可见”的错误。我该怎么办?

最佳答案

问题是元素必须是可见的。就是说即使是html的也不够,还得在浏览器上可见。尝试先单击下拉菜单以查看其元素,然后再单击其中一个元素。此外,在单击下拉列表后,不要忘记等到您的元素被显式或隐式显示。

您确定要点击它吗?如果它只是一个带有 url 的对象,请精确 url 并使用 driver.get(url)

关于python selenium 无法点击标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44897726/

相关文章:

python - 如何在Python中使用十六进制进行异或

python - 使用 Python 编码和解码二维码的库

python - 名称错误 : name "webdriver" is not defined

Java selenium - 在下拉菜单中选择元素

java - Selenium - 不一致的 StaleElementReference 错误

python - 如何在 tkinter 表 python 中对齐列标题

python - python中的字符串分割

python - Numpy 点操作未使用所有 cpu 内核

java - Selenium:WAITING元素消失

java - WebElement在浏览器中使用cssSelector、xpath可定位,虽然不为null,但为NotPresent、NotClickable、NotEnabled