英文:
How to smooth scroll inside element with Selenium[Python]
问题
我正在使用以下代码来在一个元素内滚动(动态生成的列表):
driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", element)
有没有办法进行平滑滚动(而不是当前的逐步滚动)?感觉当它跳来跳去时,我可能错过了一些数据。
英文:
I'm using
driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", element)
in order to scroll inside an element ( dynamically generated list). The code above is the only one I found that actually works and scrolls.
Is there any way to do a smooth scroll (instead of the actual step scroll)? I feel like I'm missing some data when it's jumping around.
答案1
得分: 1
你可以使用 Element#scroll
,它允许传递一个选项对象,在其中可以指定 behavior: 'smooth'
。
driver.execute_script("arguments[0].scroll({top: arguments[0].scrollHeight, behavior: 'smooth'})", element)
英文:
You can use Element#scroll
which allows passing an options object in which behavior: 'smooth'
can be specified.
driver.execute_script("arguments[0].scroll({top: arguments[0].scrollHeight, behavior: 'smooth'})", element)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论