I'm using beautifulSoup / selenium to do some webscraping and am hitting a wall with a certain dropdown select menu. The rough HTML is as follows:
<div class="selection-box" alt="selection" title="selection" role="select" tabindex="0">
<select id="select" style="display: none;">
<option value="1">First</option>
<option value="2">Second</option>
<option value="3" selected="selected">Third</option>
</select>
<div class="current">Third</div>
<ul class="options" style="display: none;">
<li class="search--option" alt="First option" title="First option" aria-label="First option" role="option" tabindex="0">First</li>
<li class="search--option" alt="Second option" title="Second option" aria-label="Second option" role="option" tabindex="0">Second</li>
<li class="search--option selected" alt="Third option" title="Third option" aria-label="Third option" role="option" tabindex="0">Third</li>
</ul>
When I'm working the menu through the browsers, it changes as follows:
- the wrapper div class changes to "selection-box active"
- the ul changes to "display: block"
- once I pick a different option, those two get reversed again and the middle div and the selected li item change accordingly
I want to use selenium to select a certain option. So far, I tried the following:
from selenium.webdriver.support.ui import Select
drpBrand = driver.find_element(By.ID, "select");
css = 'select#select' # css selector of the element
js = """const data_options = Array.from(document.querySelectorAll('{css}'));
data_options.forEach(a=>{{a.style='display:block;';}});""".format(css=css)
driver.execute_script(js)
drpBrand.select_by_visible_text("Third");
This is a best-of using various threads (element not visible: Element is not currently visible and may not be manipulated - Selenium webdriver, How to select a dropdown value in Selenium WebDriver using Java), but it still doesn't work. Any ideas? I assume I need to target the list as well (besides the select)?
The error is always
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: Element is not currently visible and may not be manipulated
Thanks