【问题标题】:In Selenium with python, after choosing drop down option page refresh but giving values of previous page在使用 python 的 Selenium 中,选择下拉选项页面刷新但给出上一页的值后
【发布时间】:2017-07-05 13:57:30
【问题描述】:

当我从下拉列表中选择下一页时,当我通过 python 程序选择值时,页面会刷新,它会为我提供上一页的值。虽然 firebug 上的相同查询达到了正确的值,但 python 程序无法在新页面中获取值。

<tr>
<td headers="SINCE">18-FEB-16</td>
<td headers="TOKEN">
<span style="font-family:mono,new courier;font-size:14;color:darkgreen;font- weight:bold">vavFeth3</span>
</td>
<td headers="STATUS">

【问题讨论】:

  • 贴出你正在使用的python代码。
  • 我认为您应该等待一段时间以显示新值(AJAX 调用、脚本等),然后使用 findElement 查询页面
  • 是的,增加超时解决了这个问题。感谢您的帮助

标签: python selenium-webdriver selenium-chromedriver


【解决方案1】:

首先我在 fetched_pa​​sswd 中获取第一页的值,然后转到下一页,然后尝试在 fetched_pa​​sswd1 中获取下一页的值,但之前的值仍在存储中。

fetched_passwd=browser.find_elements_by_xpath("//*[@headers='TOKEN']//following::span[2]")
sum=0
for i in fetched_passwd :
    print(i.text)
    sum=sum+1
    if(sum==9):
        break


next_page=browser.find_element_by_xpath("//*[@id='X01_5011970802493527']//following::option[1]").click()

fetched_passwd1=browser.find_elements_by_xpath("//*[@headers='TOKEN']//following::span[2]")
sum=0
for j in fetched_passwd1 :
    print(j.text)
    sum=sum+1
    if(sum==10):
        break 

【讨论】:

  • 有人可以帮我解决上述情况吗?
猜你喜欢
  • 2021-09-28
  • 2012-07-10
  • 1970-01-01
  • 2017-03-23
  • 1970-01-01
  • 1970-01-01
  • 2017-11-19
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多