我有一个selenium代码,在它下面可以将窗口切换到另一个窗口。如何使用HtmlUnit而不是HtmlUnitDriver来做同样的事情。
Set windows = driver.getWindowHandles(); List windowsH = new ArrayList<>(windows); driver.switchTo().window(windowsH.get(1));
有人能给我一个示例代码吗。非常感谢。
基于HtmlUnit(2.56.0(api文档:
WebClient webClient = ...
List<WebWindow> windows = webClient.getWebWindows();
webClient.setCurrentWindow(windows.get(1));
Maven依赖性
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.56.0</version>
</dependency>
参考
https://htmlunit.sourceforge.io/apidocs/index.html
https://htmlunit.sourceforge.io/apidocs/com/gargoylesoftware/htmlunit/WebClient.html#getWebWindows--
https://htmlunit.sourceforge.io/apidocs/com/gargoylesoftware/htmlunit/WebClient.html#setCurrentWindow-com.gargoylesoftware.htmlunit.WebWindow-