Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

scroll to element python selenium

from selenium.webdriver.common.action_chains import ActionChains

element = driver.find_element_by_id("my-id")

actions = ActionChains(driver)
actions.move_to_element(element).perform()
Comment

selenium scroll to element

element = driver.find_element(By.XPATH, "Whatever xpath you want")
driver.execute_script("return arguments[0].scrollIntoView();", element)
Comment

selenium scroll to element python

# this scrolls untill the element is in the middle of the page
element = driver.find_element_by_id("my-id")
desired_y = (element.size['height'] / 2) + element.location['y']
current_y = (driver.execute_script('return window.innerHeight') / 2) + driver.execute_script('return window.pageYOffset')
scroll_y_by = desired_y - current_y
driver.execute_script("window.scrollBy(0, arguments[0]);", scroll_y_by)
Comment

scroll down selenium python

browser.execute_script("window.scrollTo(0,document.body.scrollHeight)")
Comment

scroll to element selenium python

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

driver_service = Service(executable_path="C:/selenium_browser_driver/chromedriver.exe")
driver = webdriver.Chrome(service=driver_service)
site = 'https://example.com'
driver.get(site)  # opens the site in browser

element = WebDriverWait(driver, 20).until(
            EC.presence_of_element_located((By.XPATH, '//div[@class="perf-chart-container"]')))
#element = driver.find_element(By.XPATH, '//div[@class="perf-chart-container"]')
desired_y = (element.size['height'] / 2) + element.location['y']
current_y = (driver.execute_script('return window.innerHeight') / 2) + driver.execute_script('return window.pageYOffset')
scroll_y_by = desired_y - current_y
driver.execute_script("window.scrollBy(0, arguments[0]);", scroll_y_by)
Comment

PREVIOUS NEXT
Code Example
Python :: estimate time to run a chunk of code in python 
Python :: aws django migrate 
Python :: python switch case 3.10 Structural Pattern Matching 
Python :: python datetime greater than now 
Python :: how to install arcade in python 
Python :: list get every 2nd element 
Python :: plot cumulative distribution function (cdf) in seaborn 
Python :: accessing items of tuple in python 
Python :: how to make python 3 default on mac 
Python :: standardscaler 
Python :: python re search print 
Python :: numpy linspace of dates 
Python :: access class variable from another class python 
Python :: prime number checking algorithm 
Python :: python bytes 
Python :: csv to python dictionary 
Python :: python requests-session for websites with login 
Python :: pandas reset index from 0 
Python :: python print all variables in memory 
Python :: how to check if a variable in python is a specific data type 
Python :: read parquet from s3 and convert to dataframe 
Python :: python if string contains char 
Python :: how to input n space separated integers in python 
Python :: Python round to only two decimal 
Python :: python list contain list 
Python :: ValueError: query data dimension must match training data dimension 
Python :: up and down arrow matplotlib 
Python :: flatten a list 
Python :: how to add captcha in django forms 
Python :: if string in list py 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =