最近在写一个demo,发现了元素定位不到的问题,已经核对过xpath路径了,并没有出错这是怎么回事呢?

Unable to locate element

在开发者工具里时可以定位到元素的,但是控制台还是报:Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@name="startTime"]"}

Unable to locate element

网上说是chrome与chromedriver的版本不对,其实我的版本是匹配的,所以抛开这个思路。

原来定位元素仅会在当前所处的frame中寻找该元素,如果有多个frame时需要先切换到对应的frame下才能够找到该元素。

要定位到这个iframe下才能找到我要的元素:

Unable to locate element 

因此加上代码:

driver.switchTo().frame("leftContent");

 

相关文章:

  • 2022-01-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-02
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-02
  • 2022-12-23
  • 2021-07-03
  • 2021-05-05
  • 2021-04-14
相关资源
相似解决方案