JavaScript
x
2
1
<div class="InputField_Con" tabindex="-1"><div class="InputField_InputCon"><input id="TextID_Search" class="InputField_Search" type="text" role="search" autocomplete="off" style="width: 205.2px;" aria-label="* Typ:"></div></div>
2
JavaScript
1
9
1
<select class="Modern Val_Req " id="TextID" name="TextID" style="display: none;" aria-required="true">
2
<option value="">-</option>
3
<option value="1">Text1</option>
4
<option value="2">Text2</option>
5
<option value="3">Text3</option>
6
<option value="4">Text4</option>
7
<option value="5">Text5</option>
8
</select>
9
In the dropdown I’d like to select ‘Text3’, but it doesn’t work. What I tried:
JavaScript
1
4
1
driver.find_element("id", "TextID_Search").send_keys("Text3")
2
driver.send_keys(Keys.DOWN)
3
driver.send_keys(Keys.RETURN)
4
and as well:
JavaScript
1
5
1
mySelectElement = browser.find_element_by_id('TextID')
2
dropDownMenu = Select(mySelectElement)
3
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "TextID")))
4
dropDownMenu.select_by_visible_text('Text3')
5
I’m stuck and don’t know how to solve this. Need some help, thanks!
Advertisement
Answer
With Selenium, AFAIK, you cannot select elements with display:none
, if you want to force it, you’ll need to change the display property to something visible.
JavaScript
1
3
1
driver.execute_script("document.getElementById('TextID').style.display='block';")
2
// Your code to select and operate the Element by ID
3
An example about how to execute JS scritps from Selenium: https://pythonbasics.org/selenium-execute-javascript/