在 selenium 中单击 css 按钮
Clicking css buttons in selenium
我正在 Java 中处理一个测试用例,我正在使用 selenium 记录一组事件并将它们 "replay" 到应用程序。代码是:
// *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 有效但由于打开新 window 时显示的 css 横幅而无法访问。 运行 selenium IDE 给出以下事件:
Command
::Target
点击css=a.close
如何重播 Java 中的命令,以便网络驱动程序关闭横幅?
通过 CSS 选择器使用 findElement
:
driver.findElement(By.cssSelector("a.close")).click();
我正在 Java 中处理一个测试用例,我正在使用 selenium 记录一组事件并将它们 "replay" 到应用程序。代码是:
// *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 有效但由于打开新 window 时显示的 css 横幅而无法访问。 运行 selenium IDE 给出以下事件:
Command
::Target
点击css=a.close
如何重播 Java 中的命令,以便网络驱动程序关闭横幅?
通过 CSS 选择器使用 findElement
:
driver.findElement(By.cssSelector("a.close")).click();