无法通过Java中的Selenium定位位于父iframe中的子iframe元素 [英] Unable to locate the child iframe element which is within the parent iframe through Selenium in Java
问题描述
到目前为止,这就是我所拥有的:我已将框架切换到其父框架,然后又切换到了我无法找到的框架:
So far, this is what I have: I've switched the frame to its parent frame then to the the frame I am unable to locate:
By frame = By.xpath("//iframe[@class='GenCss_style-Model']");
driver.switchTo().frame(driver.findElement(By.name("documentflowdesk")));
driver.switchTo().frame(driver.findElement(frame));
由于未找到'frame'元素,因此出现此错误:
Since 'frame' element is not found, I get this error:
org.openqa.selenium.NoSuchElementException:无法找到元素
org.openqa.selenium.NoSuchElementException: Unable to locate element
HTML:
<iframe src="about:blank" name="documentflowdesk" class="gwt-Frame-NavigationComponentViewImplResourcesapplicationFrame" id="documentflowdesk" style="position: absolute; left: 0px; top: 0px; visibility: visible; height: 100%;"></iframe>
#documentflowdesk
<html style="overflow: hidden;">
<head>...</head>
<body style="margin: 0px;" class="dragdrop-dropTarget dragdrop-boundary">
<noscript>...</noscript>
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div class="css-DeskStyleResources" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<div style="position: absolute; overflow: hidden; left: 0px; top: 0px; right: 0px; bottom: 0px;">
<iframe class="GenCss_style-Model" src="/model/?modelId=100&docGroupId=164&connectionPointId=73" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px;"></iframe>
我要定位的iframe位于多个div内.它与该错误有关系吗?还是我的元素查找方式有问题?
The iframe I'm trying to locate is inside multiple div. Does it have to do anything with the error? Or is there a problem with how I find my element?
推荐答案
在HTML中,当您位于父框架上时,您必须:
As per the HTML once you are on the parent frame you have to:
- 诱导 WebDriverWait 使父框架可用并切换到它.
- 诱导 WebDriverWait 使子框架可用并切换到它.
-
您可以使用以下解决方案:
- Induce WebDriverWait for the parent frame to be available and switch to it.
- Induce WebDriverWait for the child frame to be available and switch to it.
You can use the following solution:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@class='gwt-Frame-NavigationComponentViewImplResourcesapplicationFrame' and @id='documentflowdesk']")));
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[@class='GenCss_style-Model' and contains(@src,'connectionPointId')]")));
此处您可以在在下面的方法中处理#document的方法找到相关的讨论iframe
这篇关于无法通过Java中的Selenium定位位于父iframe中的子iframe元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!