from selenium import webdriver from time import sleep from selenium.webdriver.common.action_chains import ActionChains driver = webdriver.Chrome() driver.get('https://www.baidu.com') driver.maximize_window() sleep(2) #鼠标悬停 el=driver.find_element_by_xpath("//*[@id='s-usersetting-top']") ActionChains(driver).move_to_element(el).perform() sleep(2) driver.find_element_by_xpath("//*[@id='s-user-setting-menu']/div/a[1]").click() sleep(5) driver.quit()