Sebastian Nielsen Sebastian Nielsen - 27 days ago 10
Python Question

python-selenium How to click on a option

I want to click on one of the options in one of these bad boys: https://gyazo.com/86a2f8773b182e730fe5c69107efa190
How can I make my code click it and choose the option with the

value="196277"
?

<select name="Input.MatrixElements[0].ValueId" id="matrix-element-666" data-val-required="Produkt skal udfyldes" data-val="true" data-listingtext-format=", {0}" data-listingtext-desc="" data-listingtext-priority="1" data-element-desc="Produkt" class="field-medium" data-matrixid="666">
<option value="">- Vælg -</option>
<option value="115604" data-listingtext-desc="Børneur">Børneur</option>
<option value="17662" data-listingtext-desc="Dameur">Dameur</option>
<option value="17663" data-listingtext-desc="Dykkerur">Dykkerur</option>
<option value="17661" data-listingtext-desc="Herreur">Herreur</option>
<option value="17665" data-listingtext-desc="Lommeur">Lommeur</option>
<option value="245187" data-listingtext-desc="Smartwatch">Smartwatch</option>
<option value="103440" data-listingtext-desc="Smykkeur">Smykkeur</option>
<option value="171750" data-listingtext-desc="Stopur">Stopur</option>
<option value="196277" data-listingtext-desc="Unisexur">Unisexur</option>
<option value="23395" data-listingtext-desc="Andet">Andet</option>
</select>

Answer

You can use xpath to find the particular option element :

your_choice=browser.find_element_by_xpath("//select/option[@value='196277']")

Then call the click() function on it :

your_choice.click()