selenium之窗口滚动

在这里和大家分享一下,selenium里面常用于处理窗口滚动的方法。

location_once_scrolled_into_view 一般用于定位窗口底部元素。将窗口拉到最底部。

window.scrollTo(x,y)  js方法将窗口拉动到指定的X,Y坐标上。如果需要将窗口拉到最底部,可以使用Y=document.body.scrollHeight

具体代码如下:

e=driver.find_element_by_xpath("//*[text()='联系我们']")   #需要定位到的底部元素

e.location_once_scrolled_into_view   #拉动窗口至底部

js_code='window.scrollTo(0,documet.boby.scrollHeight)'    #js方法拉动窗口至底部

driver.execute_script(js_code)   #执行js代码

猜你喜欢

转载自www.cnblogs.com/yiruiwan/p/12233886.html