2

I am working with a js heavy webpage and I have a div element which looks like so:

<div id="results-ItemSearch" class="itemresults" onscroll="loadMoreItems(event)">
....
</div>

It is one of those webpages which does autoscrolling (further complicated by the fact that there are three panes within the same window and I am having a hard time getting to the pane I want to work with), and normally, I implement something like this in selenium:

no_of_pagedowns = 1
while no_of_pagedowns:
    browser.find_element_by_xpath('/html/body').send_keys(Keys.PAGE_DOWN)
    time.sleep(1)
    no_of_pagedowns-=1

however, when I do this on this webpage, I get a selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable exception.

I tried selecting by css, but that does not yield anything either. I also tried waiting for 15 or so seconds for complete load, but that does not seem to work either.

Thus, I was wondering if there is a way to directly excecute the JS loadMoreItems(event) via selenium.

Any help will be appreciated - spent 4 hours on this now!

2
  • Have you tried driver.execute_script("arguments[0].scrollIntoView(true);", someElement)? You could locate the 'last' item inside your itemresults list, and scroll to it this way -- this should ideally trigger loadMoreItems(event). Commented Feb 4, 2020 at 17:54
  • @Christine: the problem is that I could never see the last element :( anyways, Guy's answer below worked well. Thank you for reading through my question and suggesting the answer. Commented Feb 5, 2020 at 8:27

1 Answer 1

1

You could try scrolling with JavaScript

element =  browser.find_element_by_id('results-ItemSearch')
driver.execute_script('arguments[0].scrollTo(0, arguments[0].scrollHeight)', element)

Or

driver.execute_script('scrollBy(0, arguments[0].scrollHeight))', element)
Sign up to request clarification or add additional context in comments.

1 Comment

simply put, you are a genius!! The first option worked like a charm. The second, for some reason, did not work. I would have NEVER figured this out without your help. I REALLY appreciate your time. Thank you. Answer accepted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.