硒按特定像素值滚动 [英] selenium scroll by specific pixel values

查看:48
本文介绍了硒按特定像素值滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看到 python selenium 我可以使用

I see for python selenium I can scroll to element using

self.driver.execute_script("return arguments[0].scrollIntoView(true);", element)

或者使用像素值作为

driver.execute_script("window.scrollTo(0, <vertical_position_to_scroll> )")

但是有没有办法从当前元素或当前位置按特定像素值滚动.例如如果我移动到元素,我想从那里向上滚动 10 个像素.

But is there way to scroll by specific pixel values from current element or current position. e.g. If I moved to element I want to scroll 10 pixel up from there.

推荐答案

我会使用 window.scrollBy(x, y)

像这样:

#first move to the element
self.driver.execute_script("return arguments[0].scrollIntoView(true);", element)
#then scroll by x, y values, in this case 10 pixels up
self.driver.execute_script("window.scrollBy(0, -10);")

此处您将找到关于 <代码>scrollBy.

这篇关于硒按特定像素值滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆