Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python selenium无法单击标记_Python_Selenium - Fatal编程技术网

python selenium无法单击标记

python selenium无法单击标记,python,selenium,Python,Selenium,我正在尝试单击下面显示的名为“Segment Metrix 2.0消费者目标档案报告”的按钮 我找到了相应的HTML,如下所示 我试图编写如下代码: elem = driver.find_elements_by_xpath("//*[contains(text(), 'Segment Metrix 2.0 Consumer Target Profile report ')]") print (elem) 它给了我: [<selenium.webdriver.remote.webele

我正在尝试单击下面显示的名为“Segment Metrix 2.0消费者目标档案报告”的按钮

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

我试图编写如下代码:

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")>]
[]

但我无法通过添加元素[0]来单击它。单击(),它会向我抛出一个“元素不可见”错误。我该怎么办?

尝试等待元素变为可见:

from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait

wait(driver, 10).until(EC.visibility_of_element_located((By.LINK_TEXT, "Segment Metrix 2.0 Consumer Target Profile report"))).click()

您可以等待元素可见

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

elem = driver.find_elements_by_xpath("//*[contains(text(), 'Segment Metrix 2.0 Consumer Target Profile report ')]")
WebDriverWait(driver, 10).until(EC.visibility_of(elem[0]))
elem[0].click()

问题是元素必须是可见的。这意味着即使它是html格式的,也不够,它必须从浏览器中可见。尝试先单击下拉列表以查看其元素,然后只单击其中一个元素。此外,在单击下拉列表后,不要忘记等待您的元素t将被显式或隐式地看到


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

谢谢您的回答!我尝试了,但我得到了一个timeoutexception:“selenium.common.exceptions.timeoutexception:Message:”您在单击“Segment Metrix 2.0消费者目标档案报告”之前是否单击了“Segment dec”你说得对!我没有点击dec段。只是点击了它,它就工作了!Thx;)很好的解释!我点击了下拉列表,它就工作了!Thx。是的,我必须点击它,因为url一直保持不变。