Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.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
Selenium(Python)-选择_Python_Selenium_Selenium Webdriver - Fatal编程技术网

Selenium(Python)-选择

Selenium(Python)-选择,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,现在,我的脚本转到第页,打开下拉列表中的第二个对象“Vijesti”,然后我就会收到错误消息 这就是错误: StaleElementReferenceException:Message:缓存中找不到元素-可能页面在查找后已更改 从Selenium站点: 当对元素的引用现在为“过时”时引发。 Stale表示元素不再出现在页面的DOM上。 StaleElementReferenceException的可能原因包括但不限于: 您不再在同一页面上,或者该页面可能在元素定位后已刷新 该元素可能已被移除并

现在,我的脚本转到第页,打开下拉列表中的第二个对象“Vijesti”,然后我就会收到错误消息

这就是错误:

StaleElementReferenceException:Message:缓存中找不到元素-可能页面在查找后已更改

从Selenium站点:

当对元素的引用现在为“过时”时引发。 Stale表示元素不再出现在页面的DOM上。 StaleElementReferenceException的可能原因包括但不限于:

  • 您不再在同一页面上,或者该页面可能在元素定位后已刷新
  • 该元素可能已被移除并重新添加到屏幕中,因为它已被定位。例如正在重新定位的元素。当更新值并重建节点时,javascript框架通常会发生这种情况
  • 元素可能位于已刷新的iframe或其他上下文中
我要选择的是每个对象,然后打开它

这是从url中选择的部分:

<select id="kategorija" name="kategorija">
<option value="0">Kategorija</option>
<option value="12">Vijesti</option>
<option value="8">Biznis</option>
<option value="5">Sport</option>
<option value="2">Magazin</option>
<option value="7">Lifestyle</option>
<option value="3">Scitech</option>
<option value="6">Auto</option> 
</select>
这是我做测试的地方

当从下拉列表中选择一个项目时,页面会自动刷新

您需要“重新查找”每个选项上的
select
元素,然后选择:

select = Select(driver.find_element_by_name('kategorija'))

for index in range(len(select.options)):
    select = Select(driver.find_element_by_name('kategorija'))
    select.select_by_index(index)

    # grab the results
select = Select(driver.find_element_by_name('kategorija'))

for index in range(len(select.options)):
    select = Select(driver.find_element_by_name('kategorija'))
    select.select_by_index(index)

    # grab the results