一、知识点
1、浏览上移
up = "document.documentElement.scrollTop = 0" #浏览器上移
js driver.execute_script(up) #调用js
2、浏览器下滑
down = "document.documentElement.scrollTop = 350" #浏览器下滑
js driver.execute_script(down) #调用js
二、实例
拉勾网-window最大化-浏览器下滑-下拉框定位查找
from selenium import webdriver #from selenium.webdriver.support.select import Select import time as t #下拉框的定位(没有select类),浏览器下滑 driver = webdriver.Chrome() driver.get('https://www.lagou.com/zhaopin/') driver.maximize_window() t.sleep(3) down = "document.documentElement.scrollTop = 350" #浏览器下滑js driver.execute_script(down) #调用js t.sleep(5) driver.find_element_by_xpath('//*[@id="order"]/li/div[2]/div/span').click() #定位到月薪下拉框 t.sleep(2) driver.find_element_by_xpath('//*[@id="order"]/li/div[2]/div/ul/li[6]/a').click() #月薪在15k-25k