Use*_*ser 6 python mousemove phantomjs selenium-webdriver
我正在尝试模拟鼠标在随机曲线或抛物线上的移动,因此看起来鼠标实际上在页面上移动。使用Selenium,我只知道如何单击某个元素,但这并不能模拟某些网站上的真实用户。我希望鼠标沿着我计算出的随机线移动,然后单击该元素。
Python 代码如下所示(假设您的浏览器是 Firefox):
driver = webdriver.Firefox(executable_path=driver_path)
action = webdriver.ActionChains(driver)
element = driver.find_element_by_id('your-id') # or your another selector here
action.move_to_element(element)
action.perform()
Run Code Online (Sandbox Code Playgroud)
请注意,这不会移动您的物理光标,而只会移动 Selenium 的不可见光标。要查看它是否有效,元素必须具有某种“悬停”效果。此外,如果您已经将光标移动到某个元素并想要相对地重新定位它,您可以使用:
action.move_by_offset(10, 20) # 10px to the right, 20px to bottom
action.perform()
Run Code Online (Sandbox Code Playgroud)
甚至更短:
action.move_by_offset(10, 20).perform()
Run Code Online (Sandbox Code Playgroud)
更多文档在这里: https ://selenium-python.readthedocs.io/api.html
归档时间: |
|
查看次数: |
22958 次 |
最近记录: |