WebDriverException:使用ChromeDriver Chrome和Selenium与iframe内的元素交互时,目标帧分离
我使用Chromedriver 78.0.3904.70WebDriverException:使用ChromeDriver Chrome和Selenium与iframe内的元素交互时,目标帧分离,selenium,google-chrome,selenium-webdriver,iframe,selenium-chromedriver,Selenium,Google Chrome,Selenium Webdriver,Iframe,Selenium Chromedriver,我使用Chromedriver 78.0.3904.70 WebDriverException: target frame detached exception 已发生,但在以前版本的chromedriver中,所有这些都工作正常。 现在在我的iFrame中,我在自动测试期间找不到任何元素,其中应该有另一个iFrame,但我可以手动完成。 在自动测试期间也成功切换到iFrame。我想新的chromedriver可能有一个bug?有什么想法吗 org.openqa.selenium.WebDr
WebDriverException: target frame detached exception
已发生,但在以前版本的chromedriver中,所有这些都工作正常。
现在在我的iFrame中,我在自动测试期间找不到任何元素,其中应该有另一个iFrame,但我可以手动完成。
在自动测试期间也成功切换到iFrame。我想新的chromedriver可能有一个bug?有什么想法吗
org.openqa.selenium.WebDriverException: target frame detached
(Session info: chrome=78.0.3904.97)
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'PDF323-440G4', ip: '172.16.14.147', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_181'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 78.0.3904.97, chrome: {chromedriverVersion: 78.0.3904.70 (edb9c9f3de024..., userDataDir: C:\Users\Nikolay\AppData\Lo...}, goog:chromeOptions: {debuggerAddress: localhost:64307}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: c6f28448e742438746371ee017a51dda
此错误消息
WebDriverException: target frame detached
…意味着对于某个HttpRequest结果HttpServerResponseInfo是net::HTTP\u未找到
细节 根据讨论,返回的一些错误代码不符合W3C标准。它们被替换为相应的标准错误代码:
->异步脚本超时
脚本超时
->元素不可见
元素不可交互
->没有这样的会话
无效会话id
->未创建会话异常
未创建会话
->xpath查找错误
无效选择器
无法访问chrome
断开连接
禁止
没有这样的执行上下文
选项卡崩溃
目标帧分离
深潜 错误
目标帧分离
是案例kTargetDetached
在中定义的结果,并且在HttpServerResponseInfo包含HTTP\u NOT\u FOUND时发生,如下所示:
void HttpHandler::HandleCommand(
const net::HttpServerRequestInfo& request,
const std::string& trimmed_path,
const HttpResponseSenderFunc& send_response_func) {
base::DictionaryValue params;
std::string session_id;
CommandMap::const_iterator iter = command_map_->begin();
while (true) {
if (iter == command_map_->end()) {
if (w3cMode(session_id, session_thread_map_)) {
PrepareResponse(
trimmed_path, send_response_func,
Status(kUnknownCommand, "unknown command: " + trimmed_path),
nullptr, session_id, true);
} else {
std::unique_ptr<net::HttpServerResponseInfo> response(
new net::HttpServerResponseInfo(net::HTTP_NOT_FOUND));
response->SetBody("unknown command: " + trimmed_path, "text/plain");
send_response_func.Run(std::move(response));
}
return;
}
if (internal::MatchesCommand(
request.method, trimmed_path, *iter, &session_id, ¶ms)) {
break;
}
++iter;
}
我在79版上也面临同样的问题。在我的mac电脑上更新到chrome版本80.0.3987.53(官方版本)beta(64位),并在使用selenium时使用chromedriver版本80.0.3987.16。现在切换到iframe工作正常
从上面得到一个提示,它已经在版本80中修复。希望有帮助 重试和切换帧对我有效:
public void retryForDetachedFrame(final WebDriver driver, final String elementXpath, final int frameId) throws Exception {
int webDriverExceptionCounter = 0;
while (webDriverExceptionCounter < 5) {
try {
driver.findElement(By.xpath(elementXpath));
break;
} catch (final WebDriverException ex) {
webDriverExceptionCounter++;
if (webDriverExceptionCounter == 5) {
log.error("WebDriverException, not trying again: {}", webDriverExceptionCounter);
throw ex;
} else {
log.info("WebDriverException, retrying: {}", webDriverExceptionCounter);
Thread.sleep(500);
final WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frameId));
}
} catch (final Exception e) {
log.error("Exception: {}", e.getClass());
throw e;
}
}
}
public void retryForDetachedFrame(最终WebDriver驱动程序、最终字符串元素xpath、最终int frameId)引发异常{
int webDriverExceptionCounter=0;
而(webDriverExceptionCounter<5){
试一试{
findElement(By.xpath(elementXpath));
打破
}捕获(最终WebDriverException ex){
webDriverExceptionCounter++;
如果(webDriverExceptionCounter==5){
错误(“WebDriverException,不再尝试:{}”,webDriverExceptionCounter);
掷骰子;
}否则{
log.info(“WebDriverException,重试:{}”,webDriverExceptionCounter);
睡眠(500);
最终WebDriverWait等待=新WebDriverWait(驱动程序,15);
wait.until(ExpectedConditions.frametobeavailable和switchtoit(frameId));
}
}捕获(最终异常e){
错误(“异常:{}”,e.getClass());
投掷e;
}
}
}
public void retryForDetachedFrame(final WebDriver driver, final String elementXpath, final int frameId) throws Exception {
int webDriverExceptionCounter = 0;
while (webDriverExceptionCounter < 5) {
try {
driver.findElement(By.xpath(elementXpath));
break;
} catch (final WebDriverException ex) {
webDriverExceptionCounter++;
if (webDriverExceptionCounter == 5) {
log.error("WebDriverException, not trying again: {}", webDriverExceptionCounter);
throw ex;
} else {
log.info("WebDriverException, retrying: {}", webDriverExceptionCounter);
Thread.sleep(500);
final WebDriverWait wait = new WebDriverWait(driver, 15);
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(frameId));
}
} catch (final Exception e) {
log.error("Exception: {}", e.getClass());
throw e;
}
}
}