I'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.
CodePudding user response:
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.