PS:滚动屏幕

例子

代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2019-07-15 16:12:33
# @Author  : BenLam
# @Link    : https://www.cnblogs.com/BenLam/

from selenium import webdriver
driver=webdriver.Firefox()
driver.get(r'test.html')

# 向下移动 500 个像素点,代表x, y轴
driver.execute_script("window.scrollBy(0,500)"# 同上,下降 1000 个像素点
# PS:不同的浏览器,可能或存在兼容问题
driver.execute_script("window.scrollBy(0,1000)")

driver.quit()

例子_B

PS: 滚动屏幕并定位元素, 这里我们打开博客园,定位到“统计信息”栏

代码:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Date    : 2019-07-15 16:12:33
# @Author  : BenLam
# @Link    : https://www.cnblogs.com/BenLam/

from selenium import webdriver
driver=webdriver.Firefox()
driver.get(r'https://www.cnblogs.com/')

# 先找元素
a = driver.find_element_by_xpath(r'//*[@]/div[7]/h4')

# 通过 js 方式找滚动到元素所在地方
# 打印 text 显示为 “'统计信息'”
text = driver.execute_script("return arguments[0].scrollIntoView();", a)

driver.quit()

相关文章:

  • 2021-12-08
  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2022-02-25
  • 2021-11-09
  • 2021-05-25
猜你喜欢
  • 2022-01-14
  • 2021-10-14
  • 2021-08-02
  • 2021-12-03
  • 2021-09-15
  • 2022-12-23
相关资源
相似解决方案