I need to select any element from the web element with display: none
attribute that looks like this:
<div class="some_class">
<select id="some_id" class="some_select_class" style="display: none;">
<option value="1" data-isleaf="false" data-catid="3" data-special_message="" data-adtypeid="0">1</option>
<option value="2" data-isleaf="true" data-catid="4" data-special_message="" data-adtypeid="1">2</option>
</select>
</div>
I can do it manually from a web browser, but I need to do it via Selenium in Python. Unfortunately, when I have the following code:
try:
element = selenium.webdriver.support.ui.WebDriverWait(driver, 60).until(EC.visibility_of_element_located((By.ID, 'some_id')))
selenium.webdriver.support.ui.Select(element).select_by_value('1')
except Exception as ex:
print(ex)
WebDriverWait
throws an exception with the following info:
Message: ''
The type of the exception is selenium.common.exceptions.TimeoutException
How can I achieve the interaction of this element? How can I select any element in this case?
Thanks in advance.
Use execute_script()
to set the display property of that element and then use the Selenium Select
for selecting a required value.
Below code should work for you:
try:
selenium.webdriver.support.ui.WebDriverWait(driver, 60).until(EC.visibility_of_element_located((By.ID, 'some_other_id_on_page')))
selenium.execute_script("document.getElementById('some_id').style.display='inline-block';")
element = selenium.webdriver.support.ui.WebDriverWait(driver, 60).until(EC.visibility_of_element_located((By.ID, 'some_id')))
selenium.webdriver.support.ui.Select(element).select_by_value('1')
except Exception as ex:
print(ex)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With