<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>
<select class="Modern Val_Req " id="TextID" name="TextID" style="display: none;" aria-required="true"> <option value="">-</option> <option value="1">Text1</option> <option value="2">Text2</option> <option value="3">Text3</option> <option value="4">Text4</option> <option value="5">Text5</option> </select>
In the dropdown I’d like to select ‘Text3’, but it doesn’t work. What I tried:
driver.find_element("id", "TextID_Search").send_keys("Text3") driver.send_keys(Keys.DOWN) driver.send_keys(Keys.RETURN)
and as well:
mySelectElement = browser.find_element_by_id('TextID') dropDownMenu = Select(mySelectElement) WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "TextID"))) dropDownMenu.select_by_visible_text('Text3')
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.
driver.execute_script("document.getElementById('TextID').style.display='block';") // Your code to select and operate the Element by ID
An example about how to execute JS scritps from Selenium: https://pythonbasics.org/selenium-execute-javascript/