1 from selenium import webdriver 2 3 browers=webdriver.Firefox() 4 browers.get("url") 5 name=browers.name() 6 7 ##到顶 8 def scroll_top(): 9 if name=="chrome": 10 js = "var q=document.body.scrollTop=0" 11 else: 12 js = "var q=document.doc
2
3 browers=webdriver.Firefox()
4 browers.get("url")
5 name=browers.name()
6
7 ##到顶
8 def scroll_top():
9 if name=="chrome":
10 js = "var q=document.body.scrollTop=0"
11 else:
12 js = "var q=document.documentElement.scrollTop=0"
13 return browers.execute_script(js)
14
15
16 ##到底
17 def scroll_foot():
18 if browers.name == "chrome":
19 js = "var q=document.body.scrollTop=10000"
20 else:
21 js = "var q=document.documentElement.scrollTop=10000"
22 return browers.execute_script(js)
23
24 #滚动到底部
25 js = "window.scrollTo(0,document.body.scrollHeight)"
26 browers.execute_script(js)
27 #滚动到顶部
28 js = "window.scrollTo(0,0)"
29 browers.execute_script(js)
30
31 # 聚焦元素
32 target = browers.find_element_by_xxxx()
33 browers.execute_script("arguments[0].scrollIntoView();", target)