How to click a link in a hover menu with Selenium webdriver?
<p>I am trying to click on an option in a hover menu.</p>

<p><a href="http://www.nike.com/us/en_us/c/men" rel="nofollow">http://www.nike.com/us/en_us/c/men</a></p>

<p>if you click Men in the top nav bar (not the side one), and click tops and t-shirts, that is what I'm trying to do with Selenium webdriver.</p>

<p>I currently am doing this:</p>

<pre><code># select shirt category
driver.find_element_by_css_selector("span.nsg-font-family--platform.gnav-bar--facet-label").click()
driver.find_element_by_partial_link_text("shirt").click()
</code></pre>

<p>But this seems to be choosing an option out of the left nav bar instead of the top one.</p>

<p>How can I click on "tops and t-shirts" in the top nav bar using selenium?</p>

<p>Full example:</p>

<pre><code>driver = self.driver
driver.get(self.base_url)
driver.maximize_window()
wait = WebDriverWait(driver, 10)

# choose country/region
driver.find_element_by_xpath("(//button[@type='button'])[2]").click()
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "li.US a"))).click()

#verify swoosh logo is displayed
logo = driver.find_element(By.CSS_SELECTOR, 'span.nsg-glyph--swoosh.gnav-bar--home-logo')
logo.is_displayed()

# open men's hover menu in top nav bar
men_menu = driver.find_element_by_css_selector("li[data-nav-tracking=men]")

# click shirt
men_menu.find_element_by_partial_link_text("Shirt").click()

# select a shirt for sale
driver.find_element_by_xpath("//div[@id='exp-gridwall-wrapper']/div[2]/div[2]/div[2]/div/div/div/div/div/div[3]/div[2]/p").click()

# opening size dropdown
size_button = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".exp-pdp-size-and-quantity-container a.exp-pdp-size-dropdown")))
actions = ActionChains(driver)
actions.move_to_element(size_button).click().perform()

# selecting size
size = wait.until(EC.visibility_of_element_located((By.XPATH, "//li[contains(@class, 'nsg-form--drop-down--option') and normalize-space(.) = 'XL']")))
actions = ActionChains(driver)
actions.move_to_element(size).click().perform()

# adding to cart
driver.find_element_by_id("buyingtools-add-to-cart-button").click()

# open checkout
checkout_button = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".checkout-button")))
actions = ActionChains(driver)
actions.move_to_element(checkout_button).click().perform()

# select guest checkout
guestlogin_button = wait.until(EC.visibility_of_element_located((By.ID, "ch4_loginGuestBtn")))
actions = ActionChains(driver)
actions.move_to_element(guestlogin_button).click().perform()
# driver.find_element_by_id("ch4_loginGuestBtn").click()

# filling out order form
firstname = driver.find_element_by_id("fname")
firstname.click()
firstname.clear()
firstname.send_keys("testname")
firstname.send_keys(Keys.TAB)

lastname = driver.find_element_by_id("lname")
lastname.send_keys("testname")
lastname.send_keys(Keys.TAB)

address = driver.find_element_by_id("address1Field")
address.send_keys("test address")
address.send_keys(Keys.TAB)

city = driver.find_element_by_id("singleCity")
city.send_keys("testcity")
city.send_keys(Keys.TAB)

state = driver.find_element_by_id("singleState")
state.send_keys("Oregon")
state.send_keys(Keys.TAB)

postalcode = driver.find_element_by_id("postalCodeField")
postalcode.send_keys("97202")
postalcode.send_keys(Keys.TAB)

# click next button
driver.find_element_by_id("shippingSubmit").click()

# switch to billing frame
wait = WebDriverWait(driver, 10)
driver.switch_to.frame("billingFormFrame") 

# enter credit card number
cc = wait.until(EC.element_to_be_clickable((By.ID, "creditCardNumber")))
cc.click()
cc.send_keys("4111111111111111")

# enter expiration
selectmonth = Select(driver.find_element_by_id("expirationMonth"))
selectmonth.select_by_value("10")

# enter expiration year
selectyear = Select(driver.find_element_by_id("expirationYear"))
selectyear.select_by_value("2018")

# enter security code
ccs = driver.find_element_by_id("cvNumber")
ccs.send_keys("111")

# enter phone number
phonenum = driver.find_element_by_id("phoneNumber")
phonenum.send_keys("5035035033")

# enter email
email = driver.find_element_by_id("email")
email.send_keys("test@test.com")

# click submit button
driver.find_element_by_id("billingSubmit").click()

# click place order button
driver.find_element_by_css_selector("input.ch4_btnOrange").click()

time.sleep(9)
# confirm order was succesful
bodyText = driver.find_element_by_tag_name('body').text
self.assertIn("YOUR ORDER WAS PLACED SUCCESSFULLY.", bodyText)
#driver.find_element_by_id("ch4_confirmHeading")
</code></pre>