在我的Java应用程序中,我正在尝试使用以下java代码切换到Wordpress iframe content_ifr
:
driver.switchTo().frame("content_ifr");
但不断获得以下异常:
org.openqa.selenium.NoSuchFrameException: {"errorMessage":"Unable to switch to frame","request":{"headers":{"Accept":"application/json, image/png","Connection":"Keep-Alive","Content-Length":"20","Content-Type":"application/json; charset=utf-8","Host":"localhost:15910"},"httpVersion":"1.1","method":"POST","post":"{\"id\":\"content_ifr\"}","url":"/frame","urlParsed":{"anchor":"","query":"","file":"frame","directory":"/","path":"/frame","relative":"/frame","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/frame","queryKey":{},"chunks":["frame"]},"urlOriginal":"/session/d2c0de40-6349-16e5-8bdf-f3a5c98d0edc/frame"}}
驱动程序信息:
Driver info: org.openqa.selenium.phantomjs.PhantomJSDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, handlesAlerts=false, databaseEnabled=false, version=1.9.8, platform=XP, browserConnectionEnabled=false, proxy={proxyType=direct}, nativeEvents=true, acceptSslCerts=false, driverVersion=1.1.0, locationContextEnabled=false, webStorageEnabled=false, browserName=phantomjs, takesScreenshot=true, driverName=ghostdriver, javascriptEnabled=true, cssSelectorsEnabled=true}]
我正在使用:
selenium 2.47.2
phantomjs-1.9.8-windows
有什么不对?
答案 0 :(得分:0)
我实施了一个肮脏的黑客:
List<WebElement> elements = driver.findElements(By.tagName("iframe"));
WebElement iframe = null;
for (int i = 0; i < elements.size(); i++) {
if("content_ifr".equals(elements.get(i).getAttribute("id"))) {
iframe = elements.get(i);
break;
}
}
driver.switchTo().frame(iframe);
现在可行..