0

I want to select an option from a select field using Selenium & Python.

The HTML is as follows:

<select autocomplete="off" class="style_input_item" name="AccountEnable" id="Enable" value="0" onchange="onPageDataChange()">
    <option value="0" selected="selected"><script>T("Disabled")</script>Disabled</option>
    <option value="1"><script>T("Enabled")</script>Enabled</option>
</select>

And I tried as follows:

driver.find_element_by_xpath('//*[@id="Enable"]/option[value="1"]').click()

I received that error:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="Enable"]/option[value="0"]"}

2

2 Answers 2

0

Just try:

mydriver.find_element_by_xpath('//*[@id="Enable"]/option[@value="1"]').click()

or

mydriver.find_element_by_xpath('//*[@id="Enable"]/option[2]').click()
Sign up to request clarification or add additional context in comments.

Comments

-1

Make sure you include Select:

from selenium.webdriver.support.select import Select

then

select = Select(driver.find_element_by_id('Enable'))
select.select_by_index(0)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.