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.

Bin Chen
  • 13
  • 1
  • 6
  • 1
    Try with `PeriodType = driver.find_element_by_xpath("//select[@class='period-selection select2-hidden-accessible']")` – supputuri Sep 06 '19 at 04: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()` – supputuri Sep 06 '19 at 05:00
  • @supputuri, thank you and I tried your last suggestion above and still got this: ElementNotInteractableException: Element – Bin Chen Sep 07 '19 at 01: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. – Bin Chen Sep 07 '19 at 02:23
  • @BinChen Added one more canonical target. Let me know if it helps. – undetected Selenium Sep 08 '19 at 21:11
  • @DebanjanB, thank you. Still couldn't solve this issue. I am new to stackoverflow and can not chat yet. My email is binchen.bin@gmail.com. Thank you. – Bin Chen Sep 09 '19 at 16:38

1 Answers1

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
Spencer Melo
  • 410
  • 4
  • 14
  • 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. – Spencer Melo Sep 06 '19 at 06:22
  • 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. – Bin Chen Sep 07 '19 at 01:09
  • 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')` – Spencer Melo Sep 07 '19 at 02:24
  • I did update the answer, try it again, if you are not able to solve, let's try it in chat. – Spencer Melo Sep 07 '19 at 02:37
  • 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 binchen.bin@gmail.com. Thank you. – Bin Chen Sep 09 '19 at 16:34