Automation scripts usually bumped into these type of points the place script fails when factor is current on the backside of the web page and doesn’t get positioned. As an element software program testing options and expertise in automation, we’re following the under talked about method to keep away from these form of failures.
Method:
As an alternative of scrolling web page up and down immediately you may initially watch for the web page to load efficiently after which you may scroll the window and find the factor accordingly.
This, method labored fairly effectively for us and resolved the problem with the finding parts after scrolling the window.
Right here the code snippet in python: [We wait for the page to load successfully and then scroll the entire window to locate the element.]
def page_has_loaded(self):
page_state = self.driver.execute_script('return doc.readyState;')
return page_state == 'full'
As soon as, the net web page is loaded efficiently and returned in its full state we are able to scroll your entire window the place our internet parts resides and be capable of find simply.
You may comply with this code snippet to scroll the window.
def scroll_window(self, by_locator):
self.driver.execute_script("window.scrollTo(0,doc.physique.scrollHeight)", by_locator)