简体   繁体   中英

How to select check box which generate div[i] during runtime in selenium-java?

"N" number of check boxes will get created during run time depending on the selection of previous screen..

For below xpath it is "1".

//*[@id="chargedashboard"]/div[1]/span[3]/label/span[3]

If I want to select 1,9 and 15th checkboxes ,how to write code to select during runtime.

you can write a function click(IwebElement e){e.click();} takes webelement and performs click operation on it. while calling send the dynamic xpath of element to it You can use selenium-ide or Katalon Recorder for it. find out dynamic xpath of your prefered checkboxes (use chropath extension or in DevTools Element window right click on desired tag -> copy -> copy XPath).

click(Driver.FindElement(". //*[@id="chargedashboard"]/div[1]/span[3]/label/span[3]"));
click(Driver.FindElement(". //*[@id="chargedashboard"]/div[9]/span[3]/label/span[3]"));
click(Driver.FindElement(". //*[@id="chargedashboard"]/div[15]/span[3]/label/span[3]"));

it would be helpful in future if you use,

IreadOnlyCollection<IWebElement> list;
list = Driver.findElements(By.XPath(". //*[@id="chargedashboard"]/div"))

the iterate through it using forEach loop.

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