mardi 27 décembre 2016

Select all checkboxes on HTML page with Python 3.5 & Selenium

I am trying to select all checkboxes that appear on an HTML page. The final goal is obviously to click on some of them, but I can't even manage to select them properly.

Here's the HTML:

<div class="idtTopSm">
<table cellpadding="0" cellspacing="0" border="0" summary="">
<tbody>
<tr>
<td valign="top">
<div id="leaf_53557_inp">
<table cellpadding="0" cellspacing="0" border="0" summary="">
<tbody>
<tr>
<td valign="top">
<div id="leaf_53557_ctr_1" class="inpChkBox">
<input type="checkbox" id="leaf_53557" name="leaf_53557" value="53557" title="Womens Shoes > Boots">
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td valign="top">
<span id="leaf_text_53557">Womens Shoes &gt; Boots</span>
</td>
</tr>
<tr>
<td valign="top">
<div id="leaf_57974_inp">
<table cellpadding="0" cellspacing="0" border="0" summary="">
<tbody>
<tr>
<td valign="top">
<div id="leaf_57974_ctr_1" class="inpChkBox">
<input type="checkbox" id="leaf_57974" name="leaf_57974" value="57974"     title="Kids Clothes, Shoes &amp; Accs. > Girls Shoes">
</div>
</td>
</tr>
</tbody>
</table>
</div>
</td>
<td valign="top">
<span id="leaf_text_57974">Kids Clothes, Shoes &amp; Accs. &gt; Girls             Shoes</span>
</td>
</tr>
</tbody>
</table>
</div>

So in order to select ALL checkboxes (there are 2 here, Women's Shoes > Boots & Kids' Clothes, and Shoes & Accs. > Girls' Shoes) I tried different things, but nothing worked.

I tried the XPATH method:

checkBox = driver.find_elements_by_xpath(".//input[@type='checkbox']")

But when I try to print(checkBox), it returns [ ] (=nothing). It's strange because in Firefox this XPATH give me just exactly what I need.

I also tried to select it with the class name:

checkBox = driver.find_elements_by_class_name('inpChkBox')

But again, it results in nothing when I try to print it.

How can I just generate a list of all the checkboxes on the page, in order to manipulate them after?

It seems like the id, name, etc of all checkboxes are unique and generated automatically, so I can't just select them by their ID, or Value, or Name. I need something that detects all checkboxes in the page and put them in a list.

Thanks for any help




Aucun commentaire:

Enregistrer un commentaire