简体   繁体   English

如何单击使用Selenium IDE动态命名/生成的复选框?

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

How would I locate / click the following element in Selenium IDE? 我如何在Selenium IDE中找到/单击以下元素? The text "Sample XYZ5" is dynamically generated. 文本“样品XYZ5”是动态生成的。 So is the value 99999. 值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. 由于动态生成,Selenium IDE的“记录”功能不合适。 It was only capturing the locator as 'name=sample[]' which can refer to any number of samples[] on this page. 只是将定位符捕获为“ name = sample []”,它可以引用此页面上的任意数量的sample []。

This is a data driven test, so the text between the HTML tags can be read into a variable used by the Selenium IDE. 这是一个数据驱动的测试,因此HTML标记之间的文本可以读入Selenium IDE使用的变量中。

The Selenium IDE normally has a recording function. Selenium IDE通常具有录制功能。 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. 然后,您只需观察IDE如何记录它。

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. 但是,如果要使用其他框架(例如,使用Java或Python创建自动测试或...)单击它,则应使用XPaths来定位元素。 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. 但是请注意您的XPath组合,因为如果元素没有ID,则获取唯一的XPath会有些棘手。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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