- Common ways to obtain ChromeDriver
private void myMethod () {ChromeDriver c =
new ChromeDriver()
ChromeOptions options;new ChromeDriver(options)
Capabilities capabilities;new ChromeDriver(capabilities)
- Smart code suggestions by Codota
}
/** * @return 获取当前标签页的url */ public static String getCurrentUrl() { return getBrowser().getCurrentUrl(); }
/** * 新建标签页 并打开网站 * @return 返回新标签页的句柄 */ public static String openTabAndFocus(String url) { String js = "window.open('" + BLANK + "', '_blank');"; getBrowser().executeScript(js); String newHandle = getAllHandles()[1].toString(); getBrowser().switchTo().window(newHandle); if (getBrowser().getCurrentUrl().startsWith(BLANK)) { getBrowser().get(url); return newHandle; } for (Object o : getAllHandles()) { getBrowser().switchTo().window(o.toString()); if (getBrowser().getCurrentUrl().startsWith(BLANK)) { getBrowser().get(url); return o.toString(); } } throw new RuntimeException("未找到新建的空白标签页.."); }