簡體   English   中英

單擊不是 SELECT 元素的下拉菜單的第一個元素-Python selenium

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

我有一個下拉菜單,我無法弄清楚如何單擊第一個元素。 它不是SELECT元素,所以我一直在單擊下拉菜單,等待元素可見,然后嘗試選擇第一個選項。 那一直沒有用,我不確定我錯過了什么。

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()

錯誤: selenium.common.exceptions.TimeoutException

超時錯誤讓我覺得我的 css 選擇器不正確,但我也嘗試過 xpath,但效果並沒有好多少。 有點不知所措,所以非常感謝任何想法。

改變:

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

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()

並修復定位器。 這不是主要問題,但也是問題所在。

更新。 我還找到了另一個定位器。 要查找第一個項目,請使用定位器:

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

點擊使用:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM