下面为切 webview 和 switch iframe 的代码以及输出的 webview 的 pagesourse,麻烦哪位大佬能帮忙给解决下,不胜感激
//切换 webview
private void changeDriver(By by,String iframePath) {
Set handleSet=driver.getContextHandles();
pringLog("切换前 handle:"+driver.getContext());;
for(String s:handleSet){
pringLog("webview handle:"+s);
//if(s.contains("WEBVIEW")){
// driver.context(s);
// }
}
driver.context(iframePath);
pringLog("webview handle 切换到:"+driver.getContext());
logger.error("----------"+driver.getPageSource());
By by2=By.tagName("iframe");
List elList=driver.findElements(by2);
if(elList==null||elList.size()==0){
pringLog("未找到元素 iFramePath");
}
WebElement iFrame=null;
pringLog("iframe 数量:"+elList.size());
for (WebElement webElement : elList) {
//除去隐藏元素
//if(webElement.isDisplayed()){
iFrame=webElement;
pringLog("iframe tagname---"+iFrame.getTagName());
sleep(100);
break;
//}
}
driver.switchTo().frame(iFrame);
}