简体   繁体   中英

How to click a link from a hover menu using Selenium Webdriver and Python?

http://www.nike.com/us/en_us/c/nikeid

I want to click on the 'Customize' nav link up in the top nav bar (so the one on the top, not the left) and then select Men's in the hover menu.

I can click on 'Customize', the hover menu than opens, but I am having trouble selecting Men's in that menu. I have posted my code below.

    driver.get('http://www.nike.com/us/en_us/c/nikeid')
    # open Customize hover menu in top nav bar
    men_menu = driver.find_element_by_css_selector("li[data-nav-tracking=customize]")
    actions.move_to_element(men_menu).perform()

    # click Men's
    wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "li[data-nav-tracking=men] a[data-subnav-label$=Men's]"))).click()

How do I click on the Men's link with Selenium Webdriver?

Just fix your selector to match the Men link:

wait.until(EC.visibility_of_element_located(
    (By.CSS_SELECTOR, "li[data-nav-tracking=customize] [data-nav-tracking=men] a"))).click()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM