Selecting Dynamic Element in Drop Down Menu, Selenium Python

Yu Na

I am trying to select an input box in a drop down menu. The input box itself, however, appears to be dynamic. I've looked through similar posts, but they seem to be issue specific. I've had this problem a few times now with dynamic elements, and I'm hoping to understand a general approach to working with dynamic elements.

Here are the details of the element I seek to select:

<input class="lui-search__input ng-pristine ng-valid ng-empty ng-valid-maxlength ng-touched" maxlength="5000" q-placeholder="Object.Listbox.Search" ng-model="query" ng-disabled="disabled" autocomplete="" spellcheck="false" ng-trim="false" type="text" qva-blur="blurred()" qva-focus="autoFocus" qv-escape="escape($event)" qv-enter="enter($event)" placeholder="Search in listbox" aria-invalid="false" xpath="1">

(if this isn't helpful information, please let me know and I will update).

The relative xpath changes:

//body/div[8]/div[1]/div[1]/div[1]/ng-transclude[1]/div[1]/div[3]/div[1]/article[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/input[1]

in one instance

Another instance of the relative xpath:

//body/div[7]/div[1]/div[1]/div[1]/ng-transclude[1]/div[1]/div[3]/div[1]/article[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/input[1]

I have tried to select by class and css selector with no luck. I'd really like to understand how to approach this specific issue, and also a general idea of where in an element I should play around with for future instances of dynamic elements.

Thanks!

(If the element details I provided are not helpful, the element can also be accessed with the below code:)

driver.get("https://bi.prozorro.org/sense/app/fba3f2f2-cf55-40a0-a79f-b74f5ce947c2/sheet/NFTrm/state/analysis")

driver.find_element_by_xpath("//thead/tr[1]/th[2]").click()

#the input box I am attempting to select to no avail:
while True:
        try:
            WebDriverWait(driver, 25).until(EC.presence_of_element_located((By.XPATH, "//body/div[7]/div[1]/div[1]/div[1]/ng-transclude[1]/div[1]/div[3]/div[1]/article[1]/div[1]/div[1]/div[1]/div[1]/div[1]/div[1]/input[1]")))
            break
        except TimeoutException:
            print("Loading took too much time!")
DebanjanB

The WebElement is an Angular element. So ideally to click on the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using XPATH:

    driver.get('https://bi.prozorro.org/sense/app/fba3f2f2-cf55-40a0-a79f-b74f5ce947c2/sheet/NFTrm/state/analysis')
    WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//th[@tid='st.header']//span[@title='Учасник']//following::th[@tid='st.header.search']"))).click()
    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@placeholder='Search in listbox']"))).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
    
  • Browser Snapshot:

prozorro

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

selecting from drop down list in selenium python

click on selected element in drop down menu with selenium

Click Drop Down Menu with Selenium in Python

Selenium in Python - drop-down menu

Python Selenium, Scraping dynamic drop down

Locate element with selenium Xpath for date picker drop-down menu in Python?

How to select element from drop-down menu via selenium and python?

Selecting a value from a drop-down option using selenium python

Problem in selecting a drop-down list with Selenium using Python

Python (Selenium) Selecting a drop down list from HHPRED

Inspect dynamic drop down menu

Drop down menu python

Selecting all elements in a drop-down menu

Drop down menu for selecting country then states then district

Python Selenium - Select value from drop down menu

How to select a value from drop down menu in python selenium

Python Selenium click the button once a drop-down menu is available

Cannot select an option from drop down menu Python Selenium

seleting an option from a drop down menu using selenium and python

How to select a drop-down menu value with Selenium using Python?

How to select a drop-down menu value with Selenium using Python?

How to find the number of values in a drop-down menu with Python (Selenium)

How to work with drop down menu and input text boxes in selenium and python?

Click an item in a drop-down menu using selenium Python library

web scraping and drop down menu options with Selenium in Python

python selenium select from drop-down menu

Having issue with selecting drop down in selenium webriver

Selenium Python : pick element from drop down in a span

Python - How to find an element from a disappearing drop down using selenium