Selenium---鼠标调用事件
1 from selenium import webdriver 2 import time 3 from selenium.webdriver.common.action_chains import ActionChains 4 5 driver = webdriver.Chrome() 6 7 driver.get("https://www.baidu.com/") 8 9 time.sleep(2) 10 driver.maximize_window() 11 12 # 鼠标点击事件 13 # location = driver.find_element_by_link_text('地图').click() 14 15 # 鼠标事件:找到地图右键点击 16 # map_location = driver.find_element_by_link_text('地图') 17 # ActionChains(driver).context_click(map_location).perform() 18 19 # 鼠标事件:鼠标悬停 20 # location = driver.find_element_by_link_text('更多产品') 21 # ActionChains(driver).move_to_element(location).perform() 22 23 # 鼠标拖动事件 24 # location01 = driver.find_element_by_link_text('新闻') 25 # location02 = driver.find_element_by_link_text('更多产品') 26 # ActionChains(driver).drag_and_drop(location01, location02).perform() 27 28 # 鼠标双击事件 29 # location = driver.find_element_by_link_text("地图") 30 # ActionChains(driver).double_click(location).perform() 31 32 33 time.sleep(3) 34 driver.quit()