selenium鼠标事件hover菜单弹出实战

from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
driver.get("https://www.taobao.com/")  # 打开淘宝
print(driver.title)
time.sleep(3)
# 定位鼠标移动到上面的元素————女装/内衣/家居
menu = driver.find_element_by_css_selector("body > div.screen-outer.clearfix > div.main > div > div.tbh-service.J_Module > div > ul > li:nth-child(1)")
ActionChains(driver).move_to_element(menu).perform()
time.sleep(2)
# 选中子菜单“T恤”进行点击
driver.find_element_by_partial_link_text("T恤").click()
time.sleep(2)
driver.quit()

你可能感兴趣的:(selenium)