Selenium Webdriver处理iFrame之间的切换问题

原文转自:https://blog.csdn.net/dongtianlaile/article/details/9854263

对于使用的iFrame技术的website, 使用xPath无法直接定位到元素,需要先切换到相应的frame再进行定位:

[java]  view plain  copy
  1. WebElement frame=driver.findElement(By.name("navigation"));  
  2. driver.switchTo().frame(frame);  

切换到其他frame的时候,应该先回到默认的frame再切换:

[java]  view plain  copy
  1. driver.switchTo().defaultContent();  
  2. frame=driver.findElement(By.name("detail"));  
  3. driver.switchTo().frame(frame);    

猜你喜欢

转载自blog.csdn.net/u012111923/article/details/80703936