Clicking first element of drop down menu that is not a SELECT element -Python selenium

Viewed 251

I have a drop down menu that I haven't been able to figure out how to click the first element for. It is not a SELECT element, so I have been clicking the drop down, waiting for elements to be visible, and then try selecting the first option. That has not been working, and I'm not sure what I'm missing.

driver.get("https://bi.prozorro.org/sense/app/2595af2b-985f-4771-aa36-2133e1f89df0/sheet/48781d08-1fce-489b-af05-34c253e95ec2/state/analysis#view/pEh")

#click for menu to appear
tenderercode=WebDriverWait(driver, 25).until(EC.presence_of_element_located((By.XPATH,"//span[@class='title ng-binding']")))
tenderercode.click()
sleep(3)

#entering text in menu
element = driver.find_element_by_xpath("//input[@placeholder='Search in listbox']")
element.click()
element.send_keys("test")

#click on first element  
first=WebDriverWait(driver, 40).until(EC.element_to_be_clickable((By.CSS_SELECTOR,
                                                                "body.qv-client.qv-sheet-enabled.qv-view-sheet:nth-child(2) div.ng-scope.ng-isolate-scope div.lui-popover-container.ng-scope div.qv-listbox-popover.ng-scope.lui-popover div.lui-nopad.lui-popover__body.ng-scope div.listbox-wrapper.ng-scope div.qv-object-wrapper.ng-isolate-scope article.qv-object.qvt-visualization.qv-layout-xsmall.qv-object-listbox.qv-selections-active div.qv-inner-object div.qv-object-content-container:nth-child(4) div.qv-object-content.ng-isolate-scope div.qv-listbox-container.ng-scope.qv-listbox-interactive div.qv-listbox-wrapper.searchActive div.qv-listbox-scroll-area.qv-animate.ng-isolate-scope.qv-listbox-virtual-scroll-enabled div.scroll-content:nth-child(1) ul.qv-listbox.ng-scope > li.qv-listbox-item.ng-scope.serverOptional:nth-child(1)")))

first.click()

Error: selenium.common.exceptions.TimeoutException

The timeout error makes me think my css selector is incorrect, but I've tried the xpath too, and that hasn't fared much better. A little bit at my wits end, so any ideas are much appreciated.

1 Answers

Change:

first=WebDriverWait(driver, 40).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "your locator")))
first.click()

to

WebDriverWait(driver, 40).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "your locator")))
first = driver.find_element_by_css_selector("your locator")
first.click()

And fix locator. It is not the main issue, but it's also the problem.

Update. I also find one more locator. To find the first item use the locator use:

driver.find_element_by_css_selector(".qv-listbox-item.serverOptional:nth-of-type(1)>.qv-listbox-text>span")

To click use:

driver.find_element_by_css_selector(".qv-listbox-item.serverOptional:nth-of-type(1)>.qv-listbox-text>span>span")
Related