-1

Selenium v​​4.0.0.0-alpha-1 的发行说明提到:

* Added command to open a new window.

源代码:

  public static WindowType fromString(String text) {
    if (text != null) {
      for (WindowType b : WindowType.values()) {
        if (text.equalsIgnoreCase(b.text)) {
          return b;
        }
      }
    }
    return null;
  }
}

WindowType有人可以帮助我使用Selenium v​​4.x的新方法打开选项卡/窗口吗?

4

1 回答 1

1

newWindow(WindowType typeHint)在 Selenium 4 中引入打开新窗口或标签的方法

/**
 * Creates a new browser window and switches the focus for future commands of this driver
 * to the new window.
 * <p>
 * See <a href="https://w3c.github.io/webdriver/#new-window">W3C WebDriver specification</a>
 * for more details.
 *
 * @param typeHint The type of new browser window to be created. The created window is not
 *                 guaranteed to be of the requested type; if the driver does not support
 *                 the requested type, a new browser window will be created of whatever type
 *                 the driver does support.
 * @return This driver focused on the given window
 */
WebDriver newWindow(WindowType typeHint);

示例使用

System.setProperty("webdriver.edge.driver","D:\\SomeLocation\\msedgedriver.exe");
WebDriver  driver = new EdgeDriver();
driver.get("https://www.google.com");

// This will open the new tab
driver.switchTo().newWindow(WindowType.TAB);
driver.get("http://www.google.com");

// This will open the new window
driver.switchTo().newWindow(WindowType.WINDOW);
driver.get("http://www.google.com");
于 2020-07-18T05:14:59.557 回答