转至:http://www.cnblogs.com/sylovezp/p/4329770.html

1.Exception NoSuchElementException:
  解决方法:
  1)检查目标element的locator
  2)如果locator是正确的,尝试在查找element之前等待页面的加载
  3)如果等待了很久也一直没有找到element,尝试使用另外一个locator
2.Exception NoSuchWindowException
  解决方法:
  1)检查窗口的locator
  2)在找窗口之前,等到页面的加载
3.Exception NoAlertPresentException
  解决方法:
  1)确认alert(javascript 顶层的窗口,不是最新的)是当前的
  2)在操作alert之前等待页面的加载
4.Exception NoSuchFrameException
  解决方法:
  1)检查frame的locator
  2)检查这个frame是否有一些父frame(如果有父frame的话,应该先转换到父frame)
  3)在转换到目标frame之前,确认转换到了默认的content(仅有一个frame)
  4)在转换frame之前等待页面的加载
5.Exception UnhandledAlertException
  解决方法:
  1)Check if there is some alert dialog present. ( JavaScript pop window). And deal with them.
  2)If no javascript pop window present but the exception still occurs. Make sure the developer ols 
  is closed when running automation case. (Because since selenium 2.19. “UnhandledAlertException” 
  added and they think the developer tool is an alert)
6.Exception UnexpectedTagNameException
  解决方法:
  1)Check the target element’s html tag name.
  2)Try to wait for page load then initializing the selector.
7.Exception StaleElementReferenceException
  解决方法:
  1)Re-find the element again. (Because the element has been refresh.)
8.Exception TimeoutException
  解决方法:
  1)Check the expected conditions locator.
  2)Increase the wait time.

9.org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up

  因此可以看出,在经过一次点击后,原有PageLink已经失效。需要重新获取。
  其原因在于,点击过一次PageLink后,会重新刷新并生成新PageLink,当前页的PageLink不会显示。
  用Selenium <wbr>WebDriver获取WebElement时的元素过期问题
  因此解决方法是设定了两个参数
  private Integer currentPageLinkNumber = 1;
  private Integer MaxPage = 10;//Max page links number
  然后通过
while(currentPageLinkNumber<MaxPage)
{
WebElement PageLink;
PageLink = driver.findElement(By.xpath("//a[@class = 'PageLink' and @title ='"+Integer.toString(currentPageLinkNumber+1)+"']"));
PageLink.click();
currentPageLinkNumber++;
//OtherOperation();
}
  的方式进行迭代。
  虽然感觉很麻烦就是- -
  要很小心的注意同步currentPageLinkNumber和当前的PageLink
我用的另一种方法来解决过期的问题:
int i = 1;
int j = 0;
while(i!=0){
List<WebElement> links = driver.findElements(By.xpath("//a[@href]"));
WebElement link = links.get(j);
String httpurl = "http://";
String url = link.getAttribute("href");
String text = link.getText();
System.out.println(url+" "+text);
if(url.contains(httpurl)){
//如果是隐藏的属性的话,就会报错,明天看下如何去掉隐藏元素的干扰 //*[@id='page']/div[2]/div[2]/h1/a
if(driver.findElement(By.xpath("//a[@href]")).toString().equals("http://www.1905.com/")){
continue;
}
link.click();
navigate.back();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
j++;
if(j>links.size()){
break;
}
}
}

WebDriver一些常见问题的解决方法【转】的更多相关文章

  1. WebDriver一些常见问题的解决方法

    1.Exception NoSuchElementException: 解决方法: 1)检查目标element的locator 2)如果locator是正确的,尝试在查找element之前等待页面的加 ...

  2. NHibernate常见问题及解决方法

    NHibernate常见问题及解决方法 曾经学过NHibernate的,但是自从工作到现在快一年了却从未用到过,近来要巩固一下却发现忘记了许多,一个"in expected: <end ...

  3. C#用ado.net访问EXCEL的常见问题及解决方法

    C#用ado.net访问EXCEL的常见问题及解决方法,除了像sql server,access常见的数据库,其实Excel文件也可以做为数据库访问. ado.net访问excel的实例: OleDb ...

  4. Nacos 常见问题及解决方法

    Nacos 开源至今已有一年,在这一年里,得到了很多用户的支持和反馈.在与社区的交流中,我们发现有一些问题出现的频率比较高,为了能够让用户更快的解决问题,我们总结了这篇常见问题及解决方法,这篇文章后续 ...

  5. 安装scrapy框架的常见问题及其解决方法

    下面小编讲一下自己在windows10安装及配置Scrapy中遇到的一些坑及其解决的方法,现在总结如下,希望对大家有所帮助. 常见问题一:pip版本需要升级 如果你的pip版本比较老,可能在安装的过程 ...

  6. AppFuse 3常见问题与解决方法

    非常长一段时间没做SSH项目了.近期抽出时间看了一下升级到3.x的appfuse,对新版本号使用过程中出现的一些问题进行了排查.汇总例如以下.以备后用.本文原文出处: http://blog.csdn ...

  7. python网络爬虫(1)——安装scrapy框架的常见问题及其解决方法

    Scrapy是为了爬取网站数据而编写的一款应用框架,出名,强大.所谓的框架其实就是一个集成了相应的功能且具有很强通用性的项目模板. 其实在Linux和 Mac安装,就简单的pip命令即可: pip i ...

  8. 浅谈Excel开发:九 Excel 开发中遇到的常见问题及解决方法

    Excel开发过程中有时候会遇到各种奇怪的问题,下面就列出一些本人在开发中遇到的一些比较典型的问题,并给出了解决方法,希望对大家有所帮助. 一 插件调试不了以及错误导致崩溃的问题 在开发机器上,有时可 ...

  9. 转:SVN常见问题与解决方法

    今天发现一个SVN很奇葩的问题.原来SVN提交的时候也是识别提交路径的大小写的... 发现网上有篇博客总结的挺好的.转载下来,转载出路:http://blog.csdn.net/shinn613/ar ...

随机推荐

  1. vb 修改数据库

    Dim rscode As New ADODB.Recordset ................... Set RsCode = zwpub.DataMdb.DbConnect.Execute(& ...

  2. 【Android Studio快捷键】之导入相应包声明(import packages)

    可能import 单个声明的快捷键大家都很容易找到,Alt+Enter.但是如果我要一次性import文件中所有的声明,这个快捷键是什么呢,找啊找的,就是没找到,以前在Eclipse是Ctrl+1,但 ...

  3. linux boot logo rotate

    开机logo旋转方法. 参考链接 https://www.kernel.org/doc/Documentation/fb/fbcon.txt https://community.nxp.com/thr ...

  4. rpyc 回调模式工作不正常

    rpyc 回调模式工作不正常 最近使用了 rpyc 来处理一个多节点间的文件同步的任务,目标是使用 rpyc 来实现简单的 p2p 文件传输机制,以减少单点负载和单点失败对传输的影响. 和 p2p 的 ...

  5. 第六篇 Replication:合并复制-发布

    本篇文章是SQL Server Replication系列的第六篇,详细内容请参考原文. 合并复制,类似于事务复制,包括一个发布服务器,一个分发服务器和一个或多个订阅服务器.每一个发布服务器上可以定义 ...

  6. 教你安装CentOS 6.5如何选择安装包

    近来发现越来越多的运维小伙伴们都有最小化安装CentOS 6.5系统的洁癖,因此,找老男孩来咨询,这个“洁癖”好习惯啊,必须支持,,因此发布本文和大家分享下. (1)系统安装类型选择及自定义额外包组 ...

  7. iOS 事件穿透

    - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typica ...

  8. Java基础之读文件——使用通道读二进制数据(ReadPrimes)

    控制台程序,本例读取Java基础之写文件部分(PrimesToFile)写入的primes.bin. import java.nio.file.*; import java.nio.*; import ...

  9. php基础语法学习汇总

    常量学习: <?php # function demo function sum($x,$y){ $z=$x+$y; return $z; } echo sum(1,2); #define de ...

  10. nginx字体文件配置

    http://www.doucode.com/nginx-support-font/ ====== nginx location语法 基本语法:location [=|~|~*|^~] /uri/ { ...