grxthy
grxthy

Reputation: 55

Having trouble scrolling down to element in Selenium, python

enter image description hereI'm trying to get Selenium to scroll down on a page and then click on a button (the arrows on the bottom right under the "Add+") , but I keep getting a NoSuchElementException error. Here's what I've tried, but still nothing is working.

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

element = driver.find_element_by_xpath('/html/body/div[7]/div/div/main/section[6]/main/div/main/div[2]/section[1]/p/button')
element.click()

Any help is appreciated.

Upvotes: 2

Views: 1315

Answers (1)

cruisepandey
cruisepandey

Reputation: 29382

You are using

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")

which is basically, to scroll to the bottom of the page.

Please use this :

driver.execute_script("arguments[0].scrollIntoView(true);", element)
element.click()

this will basically scroll into the element view and element will be available in Selenium view port.

Upvotes: 1

Related Questions