python---滚动条操作

"""

1、让元素滚动到可见区域后,再操作。(大部分的网页自己会滚,直接找元素---下一页)

drive.find_element("id","kw").send_keys("hhh",Keys.ENTER)
loc =(By.XPATH,'//a[text()="下一页 >"]')
WebDriverWait(drive,20).until(ec.visibility_of_element_located(loc))
els = drive.find_element(*loc).click()

2、元素本身:els.location_once_scrolled_into_view

drive.find_element("id","kw").send_keys("hhh",Keys.ENTER)
loc =(By.XPATH,'//a[text()="下一页 >"]')
WebDriverWait(drive,20).until(ec.visibility_of_element_located(loc))
els = drive.find_element(*loc)
els.location_once_scrolled_into_view

3、js代码滚动:element.scrollIntoView()

drive.find_element("id","kw").send_keys("hhh",Keys.ENTER)
loc =(By.XPATH,'//a[text()="下一页 >"]')
WebDriverWait(drive,20).until(ec.visibility_of_element_located(loc))
els = drive.find_element(*loc)
js = 'argument[0].scrollIntoView()'
drive.execute_script(js,els)

4、在f12种调试模式可以输入window.scrollIo(0,200)----根据大小滚动
posted @ 2020-10-19 15:45  随便写写。。。  阅读(695)  评论(0编辑  收藏  举报