0

How to handle dropdown without select in selenium python

here is the HTML:

Completed I want to give Completed as input and click

Here is the code

try :

            element = WebDriverWait(driver,5).until(ec.presence_of_element_located((By.XPATH,'/html/body/div[4]/div/div[2]/div/div/div[2]/div/div[2]/div[3]/div/p/div/div/span[1]/input')))   
            element.click()                                                                           
            wait = WebDriverWait(driver, 10)
            option = wait.until(ec.presence_of_element_located((By.XPATH,'//span[@class="ant-select-selection-item" and @title="Completed"]')))
            option.click()
        except:
            driver.quit()
3
  • A straightforward approach would involve initiating the dropdown by clicking on it, retrieving all the elements within the list, and then selecting the one that meets your specified condition. To ensure versatility and reusability, consider creating a generic function that can be applied to all same type of dropdowns in your application. Commented May 22, 2023 at 13:32
  • Can you correct the HTML code snippet? It starts out `class="ant-" which is not valid HTML. Commented May 22, 2023 at 19:33
  • <div class="ant-select-selector"> <span class="ant-select-selection-search"> <input type="search" autocomplete="off" class="ant-select-selection-search-input" role="combobox" aria-haspopup="listbox" aria-owns="rc_select_5_list" aria-autocomplete="list" aria-controls="rc_select_5_list" aria-activedescendant="rc_select_5_list_4" readonly="" unselectable="on" value="" id="rc_select_5" style="opacity: 0;" aria-expanded="false"> </span> <span class="ant-select-selection-item" title="Completed">Completed</span>
    – Jai Sai
    Commented May 23, 2023 at 4:51

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.