我已經嘗試了不同的選項只是爲了打開新標籤,但所有這些導致相同的結果:發送字符「t」谷歌搜索字段。 我真正的測試目標是在瀏覽器中切換標籤,但我甚至無法打開新標籤。無法創建或切換到與在MAC上的JAVA Selenium Webdriver新標籤
非常簡單的測試
public class LoginPhp2 {
@Test
public void testGoogle() {
WebDriver driver = new SafariDriver();
driver.get("https://www.google.com");
//driver.findElement(By.cssSelector("body")).sendKeys(Keys.COMMAND + "t");
Actions action= new Actions(driver);
action.keyDown(Keys.COMMAND).sendKeys("t").build().perform();
//action.keyDown(Keys.COMMAND).sendKeys("t").keyUp(Keys.COMMAND).build().perform();
}
}
所以第一個帶焦點的dom元素是搜索輸入?嘗試先模糊它? – Tim
嘗試使用javascriptexecutor。 https://troubleshootblog.com/2014/11/06/selenium-opening-a-new-tab-in-browser-firefox-chrome-or-safari/ – coolswastik