2017-09-04 83 views
1

我想用Selenium Webdriver和Java打開一個新選項卡,並且已經使用了下面的代碼,但它並沒有打開任何新的選項卡,並且在運行過程中沒有顯示任何錯誤消息。如何使用Java使用selenium webdriver打開新選項卡?

Actions act = new Actions(driver);  
act.keyDown(Keys.CONTROL).sendKeys("t").keyUp(Keys.CONTROL).build().perform(); 

使用上面的代碼我試圖通過按鍵盤上的CTRL + T打開一個新的選項卡。請幫幫我。

+0

這可能會幫助:https://stackoverflow.com/questions/12139173/how-to-open-a-new-tab-in -the-same-browser-by-using-selenium-webdriver-with-java?rq = 1 –

+0

您正在發送Keys.CONTROL兩次 –

+0

重複的https://stackoverflow.com/questions/17547473/how-to-open -a-new-tab-using-selenium-webdriver-java- –

回答

0

試試這個

String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN); 
driver.findElement(By.linkText("urlLink")).sendKeys(selectLinkOpeninNewTab); 

或使用

((JavascriptExecutor)driver).executeScript("window.open();"); 
+0

謝謝@ iamsankalp89 ..第二個工作。 –

+0

請投票 – iamsankalp89

相關問題