如何使用Selenium 4的新方法WindowType打开一个新的window

How to open a new window using the new method WindowType of Selenium 4

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;
  }
}

有人可以帮我打开一个 tab/window 使用 Selenium v4.x 的新方法 WindowType 吗?

Selenium 4

中引入了方法newWindow(WindowType typeHint)来打开新的window或选项卡
/**
 * 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");