WebDriver(Selenium2) 常见异常及处理方法

发表于:2014-12-29 13:00

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:Wind_365    来源:51Testing软件测试网采编

  Exception NoSuchElementException
  Solutions
  1. Check the locator of your target element.
  2. If the locator is current. Try to wait for page load before find element.
  3. If already wait for long time and always cannot find the element, try to use another type locator.
  Exception  NoSuchWindowException
  Solutions
  1.Check the window’s locator.
  2.Wait page load before find the window.
  Exception  NoAlertPresentException
  Solutions
  1.Make sure the alert( javascript pop window not new window) will present.
  2.Wait page load before deal the alert.
  Exception  NoSuchFrameException
  Solutions
  1.Check the frame’s locator.
  2.Check is the frame has some father frame.(if has father frame you should switch to the father frame first)
  3.Make sure switch to the default content before switch to target frame( only for single frame)
  4.Wait page load before switch to frame.
  Exception    UnhandledAlertException
  Solutions
  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 tools is closed when running automation case. (Because since selenium 2.19. “UnhandledAlertException” added and they think the developer tool is an alert)
  Exception  UnexpectedTagNameException
  Solutions
  1.Check the target element’s html tag name.
  2.Try to wait for page load then initializing the selector.
  Exception  StaleElementReferenceException
  Solutions
  1.Re-find the element again. (Because the element has been refresh.)
  Exception  TimeoutException
  Solutions
  1. Check the expected conditions locator.
  2..Increase the wait time.
  ***********************************************************************************************************
  另一篇解决元素过期的文章如下:
  用Selenium WebDriver获取WebElement时的元素过期问题 
  例如我们有一排PageLink:
  用Selenium <wbr>WebDriver获取WebElement时的元素过期问题
21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号