📜  硒滚动到元素python代码示例

📅  最后修改于: 2022-03-11 14:46:52.488000             🧑  作者: Mango

代码示例2
# 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)