python selenium鼠标滚轮点击

标签 python selenium

我有一个问题,是否可以在 python selenium 中模拟鼠标滚轮单击(当您单击链接时,浏览器中会打开一个新选项卡)或类似的东西。我使用的网站是基于 javascript 的,所以我看不到物理链接。

最佳答案

您需要执行 javascript 代码。根据 MouseEvent.button,鼠标滚轮点击具有 1 作为数字表示文档:

0: Main button pressed, usually the left button or the un-initialized state

1: Auxiliary button pressed, usually the wheel button or the middle button (if present)

2: Secondary button pressed, usually the right button

3: Fourth button, typically the Browser Back button

4: Fifth button, typically the Browser Forward button

您的 javascript 代码将是

var mouseWheelClick = new MouseEvent( "click", { "button": 1, "which": 1 });
document.getElementById('#elementToClick').dispatchEvent(mouseWheelClick)

那就简单点

driver = webdriver.Firefox()
driver.execute_script(javascript_code)

关于python selenium鼠标滚轮点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41417382/

相关文章:

python - Aerospike 数据库 - 如何附加到作为 map 值的列表

Ruby Selenium 2.0 无法获取输入标签的值

c# - 在 Selenium 中将页面几乎滚动到末尾

java - 我需要在 Eclipse(对于 Selenium WebDriver)中设置/配置哪些环境变量?如果我不设置/配置它们怎么办?

python - 在python中使用for循环生成mySQL插入语句

Python 输入 : Retrieve required keys from TypedDict definition

python - 从 Python-RQ/Redis 中删除队列

python - 创建三个类而不是两个 - keras 库

java - 在 Linux 机器上运行 testng.xml

java - Selenium:如何在 Firefox 中禁用 webdriver ="true"?