質問

Here's some hastily-scrubbed sample source from my page:

<tr><td nowrap><input type="checkbox" name="enrollments" value="1478">meta</td></tr>
<tr><td nowrap><input type="checkbox" name="enrollments" value="565">admin</td></tr>
<tr><td nowrap><input type="checkbox" name="enrollments" value="566">system</td></tr>

Going into this I won't know what number is populated in the value slot for any of these as that changes each time, and the location of the element will not always be the same index within the list (e.g., 'admin' and 'system' might be in a different order), but I will know the string of text wrapped in the table element. Is there a trick to checking that box based on the string located right next to it using Selenium?

I'm thinking I need to find the text and have it return the index within the table so I can use that index to send a click. So far I have tried every way I could think of to verify and store the text but have not been able to see where it is sitting on that table.

役に立ちましたか?

解決

You can search for td tag that contains the label that you need (admin, system, meta, ...) by xPath and take input tag.

for admin

//td[text()='admin']/input

for system

//td[text()='system']/input

for meta

//td[text()='meta']/input
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top