I would like to be able to scroll down to the bottom of a page. Reason for this is my Xpath elements are not visible until they have been scrolled to(if that makes sense). So, to be able to interact with all elements i want to scroll down to the bottom
However, only a small part of the page is scrollable (the reviews) instead of the entire page. My code for opening the page is as follows:
import pandas as pd
import re
import csv
from time import sleep
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from msedge.selenium_tools import Edge, EdgeOptions
from selenium.webdriver.common.action_chains import ActionChains
mobile_emulation = {
"deviceMetrics": { "width": 360, "height": 640, "pixelRatio": 3.0 },
"userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 10_3 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) CriOS/56.0.2924.75 Mobile Safari/535.19" }
options = EdgeOptions()
options.add_experimental_option("mobileEmulation", mobile_emulation)
options.use_chromium = True
driver = Edge(options=options)
# navigate to login screen
driver.get('https://www.google.com/maps/place/AT5/@52.3556437,4.8470182,14z/data=!4m10!1m2!2m1!1sat5!3m6!1s0x47c60995371e3933:0x50f58efcb7962ea8!8m2!3d52.3462526!4d4.8306237!9m1!1b1')
#driver.maximize_window()
driver.set_window_size(250, 1080)
driver.find_element_by_xpath('//*[@id="app"]/div[20]/div/div[2]/div/div[3]/div/span[2]/button').click()
I have tried multiple solutions, but none of them seemed to work.
I have tried
browser.execute_script("window.scrollTo(0,document.body.scrollHeight)")
and
while driver.find_element_by_tag_name('div'):
driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
Divs=driver.find_element_by_xpath('//*[@id="app"]/div[11]/div[2]/div/div[2]/div[2]/div[43]/div[2]/div') ### This is the last element i want to interact with
if 'End of Results' in Divs:
print 'end'
break
else:
continue
Nothing i have tried worked. Does anybody know how i can either
- scroll down to the bottom of the page
or
- be able to interact with the last element without it being visible at the beginning?