I'm trying to select and click in an invisible dropdown menu using selenium webdriver.
HTML:
<div id = "ID_1" style="display: none;">
.....
<select style="font-size:10px">
<option selected="selected" value="10">10</option>
<option selected="selected" value="20">20</option>
<option selected="selected" value="30">30</option>
What I've been trying to do:
sel = Select(browser.find_element_by_xpath("//select[@style='font-size:10px']"))
sel.select_by_visible_text("20")
also tried to select by value:
sel.select_by_value("20")
Both lead to the same error: ElementNotInteractableException: Message: element not interactable: Element is not currently visible and may not be manipulated
It seems like I'm able to find the elemtent, but unable to select the and click the option in the dropdown
CodePudding user response:
You first need to display the dropdown to select the option.
driver.find_element(By.XPATH, '//select[@style="font-size:10px"]').click()
This will click on the dropdown and show the options of the dropdown. Then you can click on the option.
driver.find_element(By.XPATH, '//option[@value="20"]').click()
Also need to import this
from selenium.webdriver.common.by import By
The driver.find_element_by_xpath() is deprecated in newest version.
CodePudding user response:
What I like to use (I use C#, hopefully I've translated well enough to python) is the driver's javascript execute script functionality. Here's how I normally get around not interactable errors.
driver.execute_script("arguments[0].click()", driver.find_element(By.XPATH, "xpath"));
This will use javascript to intereact with the element instead of just trying to click on it. Hope this helps :)