0

I am trying to click through the levels of a site's navigation using python and selenium. The navbar contains list items that have subelements within them.

Here is the html of the navbar:

enter image description here

The objective here is to find the element with id="ts_time", to hover over it and to click on the element within it.

So far I have tried the following selection types:

  • ID
  • XPath
  • Class_Name

Here is the ID.

time_menu_button = driver.find_element(By.ID, "ts_time")
ActionChains(driver).move_to_element(time_menu_button)

time.sleep(2.5)

This results in a NoSuchElementException

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Merv Merzoug
  • 1,149
  • 2
  • 19
  • 33
  • You say you are trying to find the element with the id "ts_time" but your code is trying to find "#imgLogo" – Bendik Knapstad Jan 23 '23 at 12:46
  • Please post the entire code and error stack to check which line it is breaking? Please post the text based HTML not the snapshot? – KunduK Jan 23 '23 at 12:58

1 Answers1

0

To hover over the element with id="ts_time" you need to invoke perform() and then to click on the element within it you can use either of the following locator strategies:

time_menu_button = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "li#ts_time")))
ActionChains(driver).move_to_element(time_menu_button).peform()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "li#ts_time > a"))).click()
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352