简体   繁体   中英

Unable to locate dynamic elements through webdriver

I'm trying to locate an dynamic element and check the checkbox. Once the checkbox is checked, automatically the list receives the value 1 . I've tried xpath /css , but without any result.

DOM :

<table class="bulk_task_table">
<tbody>
<tr class="table_row">
<td class="servicenamewrapper">
<td style="margin:0; padding:0; border:0; width:0;"></td>
<td style="margin:0; padding:0; border:0; width:0;"></td>
<td class="skill_name" width="160px">
<div id="c23743691548_ctl" style="display:inline;">
<div id="c23743691548" class="skillwrapper" style="background-color:#FFFFFF;">
<span id="c525_ctl">
<div class="renderWithName">
<div class="left">
<label for="c525">service</label>
</div>
<div class="right">
<input id="c525" class="skill48" name="c525" type="checkbox">
</div>
</div>
</span>
<span id="c526_ctl">
<select id="c526" class="listbox skill48" name="c526" size="1">
<option value="0">0</option>
<option value="1">1</option>
</select>
</span>
</div>
</div>
</td>
<tr class="table_row">
<td class="servicenamewrapper"> </td>
<td class="skill_name">
<td class="skill_name">
<td class="skill_name">
<div id="c529_ctl" style="display:inline;">
<div id="c529" class="globalswitchwrapper">
<span id="c530_ctl">
<div class="renderWithName">
<div class="left">
<label for="c530">Service</label>
</div>
<div class="right">
<input id="c530" class="skill48" name="c530" type="checkbox">
</div>
</div>
</span>
<span id="c531_ctl">
<select id="c531" class="listbox skill48" name="c531" size="1">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>

OBS: As it can view in the above code, there are two lists called "service"with the same class name.

You can select the desired dynamic elements based on their order of occurrences. For example, if you want to select the first occurring check box, you can use following xpath :

//table[@class='bulk_task_table']/descendant::input[starts-with(@class, 'skill')][1]

Similarly, if you want to select the second occurring checkbox, you can use the following xpath:

//table[@class='bulk_task_table']/descendant::input[starts-with(@class, 'skill')][2]

Moreover, in the same way, you can select other controls that are appearing in the dynamic element. For example, if you want to select the second occurrence of select control, you can use following xpath:

//table[@class='bulk_task_table']/descendant::select[starts-with(@class, 'listbox skill')][2]

If required, you can parameterize the predicate ([]) value as well. Let me know, if you have any further queries.

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