简体   繁体   中英

How to click a checkbox that's dynamically named/generated using Selenium IDE?

How would I locate / click the following element in Selenium IDE? The text "Sample XYZ5" is dynamically generated. So is the value 99999.

<td>
<input type="checkbox" value="99999" name="sample[]">
Sample #XYZ5
</td>

Because of the dynamic generation, the Selenium IDE 'record' function wasn't appropriate. It was only capturing the locator as 'name=sample[]' which can refer to any number of samples[] on this page.

This is a data driven test, so the text between the HTML tags can be read into a variable used by the Selenium IDE.

The Selenium IDE normally has a recording function. With this function you should be able to record a click on your element. Then you only have to watch how the IDE records it.

But if you want to click on it using some other frameworks (like creating an automatic test in Java or Python or...) you should use XPaths to locate the element. But be aware of your XPath combination because if the element doesn't have an ID it's a little bit tricky to get a unique XPath.

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