我正在嘗試導航到其他窗口。但Firefox新標籤,而不是新窗口打開新頁面。我檢查複選框檢查並取消選中。如何打開新窗口而不是新標籤
System.setProperty("webdriver.firefox.bin", "C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe");
System.setProperty("webdriver.gecko.driver", "C:\\Selenium Purely\\geckodriver\\geckodriver.exe");
WebDriver driver = new FirefoxDriver(); //Launches FireFox browser with blank URL
driver.get("http://the-internet.herokuapp.com/windows");
Thread.sleep(4000);
String parentwindow = driver.getWindowHandle();
System.out.println("Parent window handle is "+parentwindow);
System.out.println("Parent window title is "+driver.getTitle());
driver.findElement(By.partialLinkText("Click Here")).click();
Set <String> s1 = driver.getWindowHandles();
Iterator <String> i1= s1.iterator();
while (i1.hasNext())
{
String childwindow = i1.next();
System.out.println("Child window handle is "+childwindow);
System.out.println("Child window title is "+driver.getTitle());
if(parentwindow != childwindow)
{
driver.switchTo().window(childwindow);
Thread.sleep(4000);
}
}
所以你想打開一個新窗口點擊這裏點擊? –
是的。它是一個用於學習目的的免費網站。當我點擊點擊這裏,它不在新窗口中打開 - 並在新標籤中打開。手動地當我這樣做時,我可以在新窗口打開,因爲我已經設置了相應的屬性。但沒有解決。 – Jafar
Selenium版本3.3.1 - Firefox 52 - – Jafar