#๐Ÿ”’ Selenium "Element could not be scrolled into view" error

30 messages ยท Page 1 of 1 (latest)

peak jetty
#

I am attempting to click on a row in a table and keep getting this error even though the table row is clearly in view. After all code to navigate page I have this
parentTable = driver.find_element(By.CSS_SELECTOR , '#ctl00_MainContent_PMList_PMListGrid') row = parentTable.find_element(By.CSS_SELECTOR , '#ctl00_MainContent_PMList_PMListGrid_row0') row.click()

the webpage is made up of several nested tables (can't figure out how to copy code in inspector). I have tried scrolltoview and several other suggestions with no luck. Do I need to create an object for each layer of the table like the above? That's my next thought unless someone else has a better idea.

coarse bridgeBOT
#

@peak jetty

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

peak jetty
#

example photo of the webpage code

finite stratus
#

Sometimes when websites dynamically change (if it be redirects or other things that change the source html) it takes time for selenium to actually see the changes.

peak jetty
#

@finite stratus It's just odd I'm getting a "Element could not be scrolled into view" when the entire page fits in the view window

finite stratus
#

May i ask what website this is so i can have a look?

peak jetty
#

It's an internal website for work.

#

It is dynamic and changes based on the machinery selected. It displays preventative maintenance task that are due. Maybe an EC. function before the other statements would help.

finite stratus
#

Does the page (that you are trying to get the table) need to be loaded in from a parent site/redirect?

#

Also can we see the code. (if you need to remove the site and other pii please do).

#

!paste

coarse bridgeBOT
#
Pasting large amounts of code

If your code is too long to fit in a codeblock in Discord, you can paste your code here:
https://paste.pythondiscord.com/

After pasting your code, save it by clicking the Paste! button in the bottom left, or by pressing CTRL + S. After doing that, you will be navigated to the new paste's page. Copy the URL and post it here so others can see it.

peak jetty
#

I'm pretty sure the information displayed on the page populates from an SQL server query

#

Are you asking for my whole code or the webpage code

finite stratus
#

With selenium and dynamic websites, anything that changes and anything that happens beforehand can be part of the issue.

peak jetty
#

Gotcha one moment and I'll see if I can post the front end

#

As well as the code for the webpage. Just have to redact some stuff

finite stratus
#

the html of the website doesn't really matter to much since its a dynamic website and anything can change.

peak jetty
#

webpage

#

information in the first table changes based on the combo box to the right, second table at the bottom populates when you click on a row in the first table

finite stratus
# peak jetty information in the first table changes based on the combo box to the right, seco...
async def get_fresh_sc(driver:webdriver.Chrome, repeats:int=5):
        """
        Checks if the page source HTML changes. 
            :param driver: Driver session required to preform tasks.
            :param repeats: Maximum amount of tries to should check.
            :return: None.
        """
        wt_logger.debug(f"Checking page-source change. [Driver|{driver}, Repeats|{repeats}]")
        prev_iter = driver.page_source
        for _ in range(repeats):
            wt_logger.debug(f"Repeating check page-source. [Iter({_+1}/{repeats})]")
            if prev_iter != driver.page_source:
                wt_logger.debug(f"Page-source change detected, breaking loop. [Iter({_+1}/{repeats})]")
                break
            prev_iter = driver.page_source
            await asyncio.sleep(1)
        else:
            wt_logger.debug(f"No changes detected in page source. [Repeats|({_+1}/{repeats})]")

This is some code from my current project. The purpose of this code is to detected when the html of a site changes (really useful for dynamic websites). When you click the combo box, run the code above and when it detects a change try finding the first table. repeat this for the second table as well.

peak jetty
#

I will give it a shot. Thank you.

finite stratus
#

Its going to be hard to give a definitive solutions as each selenium project is custom made for each website. However i will try my best to help you solve this issue. If you have any other questions or need additional help on this topic, feel free to share here.

#

Additionally i urge you to read up on selenium waiting methods.
Refrences.

https://www.headspin.io/blog/using-webdriver-waits-in-selenium
https://www.selenium.dev/documentation/webdriver/waits/
https://www.selenium.dev/documentation/webdriver/drivers/options/#pageloadstrategy
Testing site -> https://www.selenium.dev/selenium/web/dynamic.html
coarse bridgeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.