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 元素不可见_Python_Selenium - Fatal编程技术网

Python 元素不可见

Python 元素不可见,python,selenium,Python,Selenium,我正试图从中获取内容。要进入下一页,我尝试单击页面底部的“下一页”按钮。我还试图通过下拉菜单更改页面,但我得到的错误是元素不可见 我甚至尝试使用actionchain作为下一页: act = ActionChains(self.driver) select_text=act.move_to_element(self.driver.find_element_by_xpath("//div[@id='pagination-group']/select[@id='pagination-select

我正试图从中获取内容。要进入下一页,我尝试单击页面底部的“下一页”按钮。我还试图通过下拉菜单更改页面,但我得到的错误是
元素不可见

我甚至尝试使用actionchain作为下一页:

 act = ActionChains(self.driver)
 select_text=act.move_to_element(self.driver.find_element_by_xpath("//div[@id='pagination-group']/select[@id='pagination-select']"))
 select_text.click().perform()
 time.sleep(4)
 option_text = self.driver.find_elements_by_xpath("//div[@id='pagination-group']/select[@id='pagination-select']/option")
 for o in option_text:
        if o.text in ('2','3','4','5','6'):
            o.click()
但我再次得到错误,在parse if o.text in('2','3','4','5','6'):' StaleElementReferenceException:消息:缓存中找不到元素-可能页面在查找后已更改

您的初始方法,
$(“a”,文本:“Pagina successiva”)。单击()可能是最好的

这看起来很容易失败。也许链接是由JS或其他东西生成的?在尝试单击之前,尝试在测试中添加睡眠,看看这是否有帮助。

您最初的方法,
$(“a”,文本:“Pagina successiva”)。单击()可能是最好的


这看起来很容易失败。也许链接是由JS或其他东西生成的?在尝试单击之前,请尝试在测试中添加睡眠,看看是否有帮助。

Selenium
Select
提供了从下拉Web元素获取
选项的方法。你可能想利用这一点,而不是试图自己选择

试试看


Selenium
Select
提供了从下拉Web元素获取
选项的方法。你可能想利用这一点,而不是试图自己选择

试试看


问题是,您要查找的链接在页面上存在两次。第一个实例隐藏在页面顶部。解决这个问题的一种方法是找到一个只存在于页面底部的容器元素。可以使用此选择器单击所需的图元。我刚刚测试过它,它工作正常

driver.get("http://www.ospedaleuniverona.it/ecm/home/per-il-paziente/unita-operative")
self.driver.find_element_by_css_selector("#pagination-container-dest a[title='Pagina successiva']").click()

问题是,您要查找的链接在页面上存在两次。第一个实例隐藏在页面顶部。解决这个问题的一种方法是找到一个只存在于页面底部的容器元素。可以使用此选择器单击所需的图元。我刚刚测试过它,它工作正常

driver.get("http://www.ospedaleuniverona.it/ecm/home/per-il-paziente/unita-operative")
self.driver.find_element_by_css_selector("#pagination-container-dest a[title='Pagina successiva']").click()