0
Serenity是基於硒的BDD。我正在使用3個窗口處理程序。我的要求是這樣的 -如何使用serinity在多個瀏覽器窗口之間導航
打開窗口1
點擊窗口1的元素,將打開的窗口2
3.click在窗口2是將一個元素打開窗口3
- 關閉所有窗口
所有窗口句柄越來越投入罰款,但我仍無法在Windows
Serenity是基於硒的BDD。我正在使用3個窗口處理程序。我的要求是這樣的 -如何使用serinity在多個瀏覽器窗口之間導航
打開窗口1
點擊窗口1的元素,將打開的窗口2
3.click在窗口2是將一個元素打開窗口3
所有窗口句柄越來越投入罰款,但我仍無法在Windows
這個工作有點正常,我在處理高達2個窗口,但不適合3之間切換 -
public class MultipleWindowsHandle {
WebDriver driver;
@Before
public void setup() throws Exception {
driver=new FirefoxDriver();
String URL="http://www.seleniummaster.com";
driver.get(URL);
driver.manage().window().maximize();
}
@Test
public void test() throws Exception {
// Opening site
driver.findElement(By.xpath("//img[@alt='SeleniumMasterLogo']")).click();
// Storing parent window reference into a String Variable
String Parent_Window = driver.getWindowHandle();
// Switching from parent window to child window
for (String Child_Window : driver.getWindowHandles())
{
driver.switchTo().window(Child_Window);
// Performing actions on child window
driver.findElement(By.id("dropdown_txt")).click();
List dropdownitems=driver.findElements(By.xpath("//div[@id='DropDownitems']//div"));
int dropdownitems_Size=dropdownitems.size();
System.out.println("Dropdown item size is:"+dropdownitems_Size);
((WebElement) dropdownitems.get(1)).click();
driver.findElement(By.xpath("//*[@id='anotherItemDiv']")).click();
}
//Switching back to Parent Window
driver.switchTo().window(Parent_Window);
//Performing some actions on Parent Window
driver.findElement(By.className("btn_style")).click();
}
@After
public void close() {
driver.quit();
}
}
//In first window - Do something to activate second window
//Actions ..... here
//Second window opens
//Following code handles second window
ArrayList<String> newTab = new ArrayList (getDriver().getWindowHandles());
getDriver().switchTo().window(newTab.get(1));
//In second window - do some actions here
ArrayList<String> newTabs = new ArrayList<String> getDriver().getWindowHandles());
getDriver().switchTo().window((newTabs.get(2)));
//In Third Window
//Do some actions here
//Close Third Window
getDriver().close(); //Disable if the action in third window closes third window like Cancel/OK button
//Switch back to second window
getDriver().switchTo().window(newTab.get(1));
//Close Second Window
getDriver().close();
//ghet back to initial (First) window
getDriver().switchTo().window(newTab.get(0));
您是否在這裏使用高級循環 – Aishu
使用此命令可以直接切換到最近的窗口。 driver.getwindowHandle() – Aishu