WebDriver一些常见问题的解决方法
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
while(currentPageLinkNumber<MaxPage) { WebElement PageLink; PageLink = driver.findElement(By.xpath("//a[@class = ‘PageLink‘ and @title =‘"+Integer.toString(currentPageLinkNumber+1)+"‘]")); PageLink.click(); currentPageLinkNumber++; //OtherOperation(); }
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; } } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。