0

I'm using selenium in python and I'm looking to select the option Male from the below:

<div class="formelementcontent">
 <select aria-disabled="false" class="Width150" id="ctl00_Gender" name="ctl00$Gender" onchange="javascript: return doSearch();" style="display: none;">
 <option selected="selected" title="" value="">
 </option>
 <option title="Male" value="MALE">
 Male
 </option>
 <option title="Female" value="FEM">
 Female
 </option>
 </select>

Before selecting from the dropdown, I need to switch to iframe

driver.switch_to.frame(iframe)

I've tried many options and searched extensively. This gets me most of the way.

driver.find_element_by_id("ctl00_Gender-button").click()
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "ctl00_Gender")))
select=Select(driver.find_element_by_id("ctl00_Gender"))
check=select.select_by_visible_text('Male')

If I use WebDriverWait it times out.

I've tried selecting by visible text and index, both give:

ElementNotInteractableException: Element could not be scrolled into view

asked Mar 30, 2020 at 10:07

2 Answers 2

1

As per the HTML you have shared the <select> tag is having the value of style attribute set as display: none;. So using Selenium it would be tough interacting with this WebElement.

If you access the DOM Tree of the webpage through , presumably you will find a couple of <li> nodes equivalent to the <option> nodes within an <ul> node. You may be required to interact with those.

You can find find a couple of relevant detailed discussions in:

answered Mar 30, 2020 at 11:51
Sign up to request clarification or add additional context in comments.

Comments

0

Try below solutions:

Solution 1:

select = Select(driver.find_element_by_id('ctl00_Gender'))
select.select_by_value('MALE')

Note add below imports to your solution :

from selenium.webdriver.support.ui import Select

Solution 2:

driver.find_element_by_xpath("//select[@id='ctl00_Gender']/option[text()='Male']").click()
answered Mar 30, 2020 at 10:30

2 Comments

Tried that and still getting the error, Element could not be scrolled into view. Also edited original post to add that I switch to iframe before selecting
use Action class/ javascript to move on to element and then select a value from drop-down

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.