0

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.

6
  • 1
    Try with PeriodType = driver.find_element_by_xpath("//select[@class='period-selection select2-hidden-accessible']") Commented Sep 6, 2019 at 4:59
  • 1
    If you want to choose the item quarterly then try driver.find_element_by_xpath("//select[@class='period-selection select2-hidden-accessible']/option[.='Quarterly']").click() Commented Sep 6, 2019 at 5:00
  • @supputuri, thank you and I tried your last suggestion above and still got this: ElementNotInteractableException: Element <option> could not be scrolled into view Commented Sep 7, 2019 at 1:08
  • @DebanjanB, thank you but I had tried the WebDriverWait approach according to the link you suggested, and got the TimeoutException message, before posting my question originally, thus I think my question is not duplicated, at least not to my knowledge yet. I look forward to your advice. Thank you. Commented Sep 7, 2019 at 2:23
  • @BinChen Added one more canonical target. Let me know if it helps. Commented Sep 8, 2019 at 21:11

1 Answer 1

0

"aria-hidden" don't really means that the element is hidden, aria stands for Accessible Rich Internet Applications, the intention is to make applications more accessible to people with disabilities.

This error means that something (other element for example) is on top (overlay) of your element.

Try to scroll to the element BEFORE you use it, like:

dropdown = driver.find_element_by_css_selector('.period-selection')

actions = ActionChains(driver)
actions.move_to_element(dropdown).perform()

Select(dropdown).select_by_visible_text('Quarterly')

You need to import the ActionChains

from selenium.webdriver.common.action_chains import ActionChains
Sign up to request clarification or add additional context in comments.

5 Comments

If in some case the the element is hidden via CSS, you will not be able to use Select, and will need to do as @supputuri comments, or in the worst case you will need to edit the element.
Hi @Spencer Melo, I got "AttributeError: move_to requires a WebElement" when I tried "actions.move_to_element(dropdown ).perform()" above. Please advise. Thank you.
Try to move outside the select, follow the code: dropdown = driver.find_element_by_css_selector('.period-selection') actions = ActionChains(driver) actions.move_to_element(dropdown).perform() Select(dropdown).select_by_visible_text('Quarterly')
I did update the answer, try it again, if you are not able to solve, let's try it in chat.
Hi Spencer Melo, thank you but I am new to Stackoverflow and I don't have the chat privilege yet. Still not able to solve the issue yet. My email is [email protected]. Thank you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.