简体   繁体   中英

selecting checkboxes in a popup window using selenium webdriver

I have a textbox and a popup window opens on click of this textbox. This popup window contains checkboxes. I want to click on the above textbox and move the focus to the popup window, select the checkboxes in the popup window and move the focus back to main window. Image of source code of the popup window is attached in the image tab.

Firefox v33.1 Selenium v2.25

source code

I tried with the below code but it didnt work:

driver.findElement(By.id("FieldView_ctl17_MultiSelect1_InputText")).click();
driver.switchTo().activeElement();
driver.findElements(By.id("checkbox0")).click();

You need to switch on open popup window before finding checkbox as below:-

//First store parent window to switch back
String parentWindow = driver.getWindowHandle();

//Perform the click operation that opens new window
driver.findElement(By.id("FieldView_ctl17_MultiSelect1_InputText")).click();

//Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
    if(!winHandle.equals(parentWindow)) {
        driver.switchTo().window(winHandle);
    }
}

//Now find checkbox and click 
driver.findElements(By.id("checkbox0")).click();

//Now close opened popup window 
driver.close();

//Switch back to parent window 
driver.switchTo().window(parentWindow);

//Continue with parent window 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM