zoukankan      html  css  js  c++  java
  • selenium.common.exceptions.StaleElementReferenceException 报错原因

    原因是点击第二个时已经是新页面,找不到之前页面的元素

    报错代码段

    elem_pic = driver.find_elements_by_xpath("//div[@class='imgpage']/ul/li/div/a/img")
    for i in elem_pic:
        elem_url = i.get_attribute("src")
        driver.get(elem_url)
        urlretrieve(elem_url,"m"+str(c)+".jpg")

    报错:

    selenium.common.exceptions.StaleElementReferenceException: Message: {"errorMessage":"Element does not exist in cache","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:50811","User-Agent":"Python http auth"},"httpVersion":"1.1","method":"GET","url":"/attribute/src","urlParsed":{"anchor":"","query":"","file":"src","directory":"/attribute/","path":"/attribute/src","relative":"/attribute/src","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/attribute/src","queryKey":{},"chunks":["attribute","src"]},"urlOriginal":"/session/e23a6270-ad9c-11e7-9d81-eb604b74f70b/element/:wdc:1507627515312/attribute/src"}}

    只要刷新页面之后重新获取元素就行,不要提前获取一组元素,然后去循环操作每一个元素,这种情况还是获取元素的个数,然后在循环中获取相应位置的元素,在用的时候才去获取

    遇到页面有变化的情况,不要去循环元素,去循环个数或者定位方式,在循环中获取元素

  • 相关阅读:
    MySQL性能优化
    性能测试结果分析
    TFS使用之代码管理
    新博开通,近期将推出系列博客之测试工具篇!
    绝对受用的TFS操作指南
    2008 & 2005 TFS 安装心得及安装时遇到的问题!
    测试用例如何进行评审?
    cordova H5打包APK关键几点记录
    Silverlight+wcf 结合窗体验证演示
    两道js笔试题
  • 原文地址:https://www.cnblogs.com/AbsolutelyPerfect/p/7647158.html
Copyright © 2011-2022 走看看