Selenium(Python)-选择
现在,我的脚本转到第页,打开下拉列表中的第二个对象“Vijesti”,然后我就会收到错误消息 这就是错误: StaleElementReferenceException:Message:缓存中找不到元素-可能页面在查找后已更改 从Selenium站点: 当对元素的引用现在为“过时”时引发。 Stale表示元素不再出现在页面的DOM上。 StaleElementReferenceException的可能原因包括但不限于:Selenium(Python)-选择,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,现在,我的脚本转到第页,打开下拉列表中的第二个对象“Vijesti”,然后我就会收到错误消息 这就是错误: StaleElementReferenceException:Message:缓存中找不到元素-可能页面在查找后已更改 从Selenium站点: 当对元素的引用现在为“过时”时引发。 Stale表示元素不再出现在页面的DOM上。 StaleElementReferenceException的可能原因包括但不限于: 您不再在同一页面上,或者该页面可能在元素定位后已刷新 该元素可能已被移除并
- 您不再在同一页面上,或者该页面可能在元素定位后已刷新
- 该元素可能已被移除并重新添加到屏幕中,因为它已被定位。例如正在重新定位的元素。当更新值并重建节点时,javascript框架通常会发生这种情况李>
- 元素可能位于已刷新的iframe或其他上下文中
<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