ActionChains 代码写法
链式写法
menu = driver.find_element_by_css_selection(".nav") hidden_submenu = driver.find_element_by_css_selector(".nav #submenu1") ActionChains(driver).move_to_element(menu).click(hidden_submenu).perform()分布写法
menu = driver.find_element_by_css_selevtor(".nav") hidden_submenu = driver_find_element_by_css_selector(".nav #submenu1") actions = ActionChains(driver) actions.move_to_element(menu) actions.click(hidden_submenu) actions.perform()扩展:
PyAutoGUI 是一个纯Python的GUI自动化工具,其目的是可以用程序自动控制鼠标和键盘操作
# 安装方法: pip install pyautogui例子:
#引入鼠标操作的ActionChains类 from selenium.webdriver import ActionChains #引入PyAutoGUI import pyautogui driver = webdriver.Firfox() driver.get("https://www.baidu.com") #定位到要右击的元素 right_click = driver.find_element_by_id("") #对定位到的元素实现鼠标右键操作 ActionChains(driver).context_click(right_click).perform() # 选中右键菜单中第二个选项 pyautogui.typewrite(['down','down'])