鼠标不显示的问题

来源:12-5 使用selenium操作浏览器的启动和访问网页

慕标5054045

2024-03-09

想达到效果:程序执行后,鼠标自动移动到百度首页的“更多”处。
问题求助:程序执行后,为什么看不到鼠标在移动,而且页面上也看不到鼠标。
代码如下:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
driver.maximize_window()
driver.get(‘https://www.baidu.com/’)
ac = ActionChains(driver)
ac.move_to_element(driver.find_element(By.CSS_SELECTOR, ‘[name=“tj_briicon”]’)
).perform()

写回答

1回答

小布_老师

2024-03-13

Help on class ActionChains in module selenium.webdriver.common.action_chains:

class ActionChains(builtins.object)
 |  ActionChains(driver, duration=250)
 |  
 |  ActionChains are a way to automate low level interactions such as
 |  mouse movements, mouse button actions, key press, and context menu interactions.
 |  This is useful for doing more complex actions like hover over and drag and drop.
 |  
 |  Generate user actions.
 |     When you call methods for actions on the ActionChains object,
 |     the actions are stored in a queue in the ActionChains object.
 |     When you call perform(), the events are fired in the order they
 |     are queued up.


ActionChains本身不是操作鼠标,而是模拟鼠标,进行元素的拖动、点击、滑动等等效果。

ActionChains是队列操作,使用时请注意顺序,以及等待时间的间隔,特别是网络响应时间。

Selenium支持浏览器,界面和无界面模式,所以本身的行为操作,不可能拖动鼠标。


https://img1.sycdn.imooc.com/szimg/65f1514009b3fea227281542.jpg

0
0

Python多领域场景实战课 快速成为多面手

Python多领域场景实战课 快速成为多面手

171 学习 · 40 问题

查看课程