有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

selenium中的java点击css按钮

我正在用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会产生以下事件:

Command::Target

单击css=a.close

如何在Java中重播该命令,以便web驱动程序关闭横幅


共 (1) 个答案

  1. # 1 楼答案

    通过CSS选择器使用findElement

    driver.findElement(By.cssSelector("a.close")).click();