0

I need to click on the dropdown list of items that are hidden and only the list visible once we click on the particular search box.

HTML TAG:

<div class="main-search_suggestions suggestions-list-container search-suggestions-list-container hidden" data-component-bound="true">
   <ul class="suggestions-list" role="listbox" aria-label="Search results">
       <li class="item suggestion suggestions-list-item " role="option" tabindex="0" aria-label="category" data-suggestion-type="category" data-param-type="find_desc" data-suggest-query="Restaurants" data-ajax-data="null">
       <li class="item suggestion suggestions-list-item " role="option" tabindex="0" aria-label="category" data-suggestion-type="category" data-param-type="find_desc" data-suggest-query="Universities" data-ajax-data="null">
       <li class="item suggestion suggestions-list-item " role="option" tabindex="0" aria-label="category" data-suggestion-type="category" data-param-type="find_desc" data-suggest-query="Hospitals" data-ajax-data="null">
       <li class="item suggestion suggestions-list-item " role="option" tabindex="0" aria-label="category" data-suggestion-type="category" data-param-type="find_desc" data-suggest-query="Hotels" data-ajax-data="null">
      </li>
   </ul>
</div>

from the above Html how to click those lists of items with either XPath/tag_name/class_name in python selenium based on the index value ?.

EDIT: (My code)

   def vendor_list():
    zipcode = (str(input("enter the zipcode:")))
    driver = open_driver_connection()
    print("Openning")
    driver.get('URL OF MY WEB PAGE')
    zipcode_value = driver.find_element_by_id('dropperText_Mast')
    zipcode_value.clear()
    zipcode_value.send_keys(zipcode)
    service_box = WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.ID,"find_desc"))).click()
    drop_down = driver.find_elements_by_xpath("//*[@id='header_find_form']/div/div[1]/div/div/ul/li") 
    for lists in drop_down: 
        lists.click()
        time.sleep(1)

2
  • Can you click on the search box first, as a normal user would have to do? Commented Apr 8, 2021 at 7:07
  • yes, once after clicking the search box the hidden dropdown will be listed. as a normal user, we should select accordingly Commented Apr 8, 2021 at 8:51

1 Answer 1

1
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"xpath of drop down"))).click()
WebDriverWait(driver,10).until(EC.visibility_of_element_located(
    (By.XPATH, "xpath of drop down list")))
WebDriverWait(driver,10).until(EC.element_to_be_clickable(
    (By.XPATH, "xpath of drop option"))).click()

Click on the dropdown , wait for the visibility of list , and then click on the option from the list

10
  • Got an error: __init__() missing 1 required positional argument: 'timeout' Commented Apr 8, 2021 at 11:13
  • updated missed intializing webdriver wait Commented Apr 8, 2021 at 11:17
  • thanks @steve. incase if i need to select the list one after the another and run as per my requirement how should i need to do it ? Commented Apr 8, 2021 at 11:25
  • @Ammu you have to repeat the 3 step , again in loop Commented Apr 8, 2021 at 11:31
  • could you accept the answer if it helped :) Commented Apr 8, 2021 at 11:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.