why python helium option value fails with CSS selector

175 views Asked by At

I have the following html fragment.

<select id="priority1" class="selectPriority form-control">
    <option value="/ABCD" selected="selected">
        10 Parameter x100
    </option>
    <option value="DEF">
        10 Parameter x150
    </option>
</select>

Using the below CSS selector to select all the option tag fails

find_all(S("#priority1 > option"))

However this works

[                                                              
    options.web_element.find_elements_by_tag_name("option")    
    for options in find_all(S("#priority1"))                   
]  

         

I am unable to understand this weird behavior can anyone please explain as whats going on

1

There are 1 answers

3
undetected Selenium On

As per the documentation in CSS Selector Reference

Selector          Example   Example description
--------          -------   -------------------
element element   div p     Selects all <p> elements inside <div> elements
element>element   div > p   Selects all <p> elements where the parent is a <div> element

So find_all(S("#priority1 > option")) would select all the <option> elements where the parent element's id attribute value is #priority1. Hence instead of selecting all the <option> elements, it would select only one.


Solution

To select all the <option> tags you need to use:

find_all(S("#priority1 option"))