When using Python Selenium to scrape a webpage with a hidden drop-down select element, I got the message "ElementNotInteractableException: Element could not be scrolled into view".
Here is the section of the webpage:
<select class="period-selection select2-hidden-accessible" tabindex="-1" aria-hidden="true" style="">
<option value="quarterly">Quarterly</option>
<option value="annual" selected="selected">Annual</option>
<option value="ttm">TTM by Quarter</option></select>
The particular select
element has no id or name and appears to be hidden
("aria-hidden = True")
.
I couldn't find the xpath (I got /html/body/div[1]/div[1]/div/div[1]/div/div/div[2]/div[2]/div[2]/div[2]/select
), although it looks like the css_selector is usable. I have tried the select
methods in Selenium as below but have no success so far.
PeriodType = Select(driver.find_element_by_css_selector('.period-selection'))
PeriodType.select_by_value('quarterly') #got "ElementNotInteractableException: Element <option> could not be scrolled into view"
PeriodType.select_by_index(1) #got "ElementNotInteractableException: Element <option> could not be scrolled into view"
PeriodType.select_by_visible_text('Quarterly') #got "ElementNotInteractableException: Element <option> could not be scrolled into view"
I also saw suggestion using
PeriodType = driver.find_element_by_css_selector('.period-selection')
driver.execute_script("arguments[0].scrollIntoView();", PeriodType)
but this hasn't worked for me so far either or I am not sure how to implement.
I also have tried to use WebDriverWait as: PeriodType = driver.find_element_by_xpath("//select[@class='period-selection select2-hidden-accessible']") dropDownMenu = Select(PeriodType) WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//select[@class='period-selection select2-hidden-accessible']//options[contains('Quarterly')]"))) dropDownMenu.select_by_visible_text('Quarterly')
However, I got "raise TimeoutException(message, screen, stacktrace)
TimeoutException" message with the code above.
I would like to be able to automatically choose quarterly
.