python---滚动条操作

2023-06-14,,

"""

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)----根据大小滚动

python---滚动条操作的相关教程结束。

《python---滚动条操作.doc》

下载本文的Word格式文档,以方便收藏与打印。