【发布时间】:2020-09-29 13:00:37
【问题描述】:
我开发了一些自动测试,它们在本地运行良好,但使用 RemoteWebDriver、IE11 失败。 该页面由 IFrame 组成,它只是我找不到元素的框架之一。其他框架工作正常。 我检查了该特定 IFrame 的 HTML,发现远程运行时 HTML 无效(driver.getPageSource())。它错过了几个关闭标签。 但是在本地运行时,HTML 是正确的。因此,无法到达元素。在使用 RemoteWebDriver 时,是否有人有可能使 HTML 有效的解决方案?
它与 chrome 完美配合(HTML 使用 RemoteWebDriver 有效)但不幸的是我被 Internet Explorer 卡住了。 :(
先决条件
- Windows 10
- Selenium-java 版本:3.141.59
- 驱动版本:IEDriverServer_Win32_3.141.5
示例:WebDriver(本地)
<li id="foldheader">Export Collection</li>
<ul id="foldinglist" style="display: none;">
<li id="foldheader">EXCO Registration</li>
<ul id="foldinglist" style="display: none;">
<span>
<li id="list">
<a id="listdel" onmouseover="mOVER(this)" onmouseout="mOUT(this)" href="javascript:mCLICK(str);" substr="ID=D1901&Module=Export Collection&Group=EXCORegistration&Function=Create Collection&GroupId=X4820">Create Collection</a>
</li>
</span>
<span>
<li id="list">
<a id="listdel" onmouseover="mOVER(this)" onmouseout="mOUT(this)" href="javascript:mCLICK(str);" substr="ID=D2336&Module=Export Collection&Group=EXCORegistration&Function=Create Collection(Copy Existing)&GroupId=X4820">Create Collection(Copy Existing)</a>
</li>
</span>
<span>
<li id="list">
<a id="listdel" onmouseover="mOVER(this)" onmouseout="mOUT(this)" href="javascript:mCLICK(str);" substr="ID=D1929&Module=Export Collection&Group=EXCORegistration&Function=Acknowledgement&GroupId=X4820">Acknowledgement</a>
</li>
</span>
<span>
<li id="list">
<a id="listdel" onmouseover="mOVER(this)" onmouseout="mOUT(this)" href="javascript:mCLICK(str);" substr="ID=D1886&Module=Export Collection&Group=EXCORegistration&Function=Process MT410&GroupId=X4820">Process T410</a>
</li>
</span>
<span>
<li id="list">
<a id="listdel" onmouseover="mOVER(this)" onmouseout="mOUT(this)" href="javascript:mCLICK(str);" substr="ID=D3285&Module=Export Collection&Group=EXCORegistration&Function=Process Collection from CE&GroupId=X4820">Process Collection from CE</a>
</li>
</span>
</ul>
</ul>
示例:RemoteWebDriver(缺少关闭标签)
<LI id=foldheader>Export Collection
<UL id=foldinglist style="DISPLAY: none">
<LI id=foldheader>EXCO Registration
<UL id=foldinglist style="DISPLAY: none">
<SPAN>
<LI id=list>
<A onmouseover=mOVER(this) onmouseout=mOUT(this) id=listdel href="javascript:mCLICK(str);" substr="ID=F05030701901&Module=Export Collection&Group=EXCORegistration&Function=Create Collection&GroupId=G49082300552">Create Collection</A>
</SPAN>
<SPAN>
<LI id=list>
<A onmouseover=mOVER(this) onmouseout=mOUT(this) id=listdel href="javascript:mCLICK(str);" substr="ID=F05030702336&Module=Export Collection&Group=EXCORegistration&Function=Create Collection(Copy Existing)&GroupId=G49082300552">Create Collection(Copy Existing)</A>
</SPAN>
<SPAN>
<LI id=list>
<A onmouseover=mOVER(this) onmouseout=mOUT(this) id=listdel href="javascript:mCLICK(str);" substr="ID=F05030701929&Module=Export Collection&Group=EXCORegistration&Function=Acknowledgement&GroupId=G49082300552">Acknowledgement</A>
</SPAN>
<SPAN>
<LI id=list>
<A onmouseover=mOVER(this) onmouseout=mOUT(this) id=listdel href="javascript:mCLICK(str);" substr="ID=F05030701886&Module=Export Collection&Group=EXCORegistration&Function=Process MT410&GroupId=G49082300552">Process MT410</A>
</SPAN>
<SPAN>
<LI id=list>
<A onmouseover=mOVER(this) onmouseout=mOUT(this) id=listdel href="javascript:mCLICK(str);" substr="ID=F05030703285&Module=Export Collection&Group=EXCORegistration&Function=Process Collection from CE&GroupId=G49082300552">Process Collection from CE</A>
</SPAN>
</LI>
</UL>
</UL>
测试源码sn-p
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.ie.InternetExplorerOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.net.URL;
import java.sql.Driver;
public class IETest {
private static void internetExplorerTest() {
//WebDriver driver;
RemoteWebDriver driver;
URL url =null;
try{
url = new URL("<remote url>");
} catch(Exception e) {
}
//Setting the webdriver.chrome.driver property to its executable's location
System.setProperty("webdriver.ie.driver", "C:\\IEDriverServer_Win32_3.141.5\\IEDriverServer.exe");
InternetExplorerOptions ieOptions = new InternetExplorerOptions();
ieOptions.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true);
ieOptions.setCapability(InternetExplorerDriver.REQUIRE_WINDOW_FOCUS, true);
//driver = new InternetExplorerDriver(ieOptions);
driver = new RemoteWebDriver(url, ieOptions);
driver.get("<url>");
WebDriverWait wait = new WebDriverWait(driver,10);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("FunctionList")));
driver.switchTo().frame("FunctionList");
// Check HTML in frame (Returns invalid HTML when using RemoteWebDriver. Missing close-tags)
System.out.println(driver.getPageSource());
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[text()='Export Collection']"))).click();
driver.quit();
}
public static void main (String[] args) {
internetExplorerTest();
}
}
很遗憾,由于安全原因,我无法为您提供 IFrame 中的整个 HTML。但是模式就像上面的 RemoteWebDriver HTML。缺少 li-close-tags。
【问题讨论】:
-
看起来您已经发布了在本地 IE 中获得的输出和在远程 Web 驱动程序中获得的输出。我建议您发布您的硒代码和该 iframe 中的 HTML 代码。它可以帮助我们对其进行测试并检查问题。
-
@Deepak-MSFT 谢谢你的回答。我添加了一些测试代码,但不幸的是,由于安全原因,我无法上传整个 HTML。
标签: java selenium internet-explorer remotewebdriver