我有一个问题,是否可以在 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/