首页 技术 正文
技术 2022年11月9日
0 收藏 489 点赞 2,436 浏览 2426 个字

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;
}
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,488
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,903
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,737
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,489
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,128
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,290