我正在使用 Java 编写一个测试用例,并使用 selenium 记录一组事件并将它们“重播”到应用程序。代码是:
// *The app opens a new window*
// Get handle of the main window
String mainWindowHnd = webDriver.getWindowHandle();
// Get all open window handlers
Set openWindows = webDriver.getWindowHandles();
Iterator ite=openWindows.iterator();
// Select the new windows (there are two that are open)
while(ite.hasNext())
{
String popupHandle=ite.next().toString();
if(!popupHandle.contains(mainWindowHnd))
{
webDriver.switchTo().window(popupHandle);
}
}
WebElement liveId = webDriver.findElement(By.id("c_clogoc"));
最后一条语句的 id 有效,但由于打开新窗口时显示的 css 横幅而无法访问。运行 selenium IDE 会产生以下事件:
命令
::目标
点击 css=a.close
如何在 Java 中重播命令以便 Web 驱动程序关闭横幅?
最佳答案
通过 CSS 选择器使用 findElement
:
driver.findElement(By.cssSelector("a.close")).click();
关于java - 单击selenium中的CSS按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35465122/