簡體   English   中英

無法單擊下拉按鈕 selenium Python

[英]Can't click on dropdown button selenium Python

我想單擊元素“項目”以顯示下拉列表(見下圖)在其他地方使用 python 中的 selenium 庫我得到錯誤:

could not be scrolled into view

例如,使用以下代碼獲得:

driver = webdriver.Firefox()
driver.get(url)
driver.find_element_by_xpath('//div[@class="multiselect-container"]').click()

或者使用一些代碼來等待元素被顯示,例如像這里描述的那樣: 消息:在嘗試通過 Selenium 單擊下拉菜單中的選項時,元素 <option> 無法滾動到視圖中

mySelectElement = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.ID, "edit-projects")))
mySelectElement.click()

但我無法讓它工作。

任何將不勝感激。

可以在此處找到 html 源代碼:

https://rpidejr.hopto.org/f/8a909b51dcc34d09a00a/

在此處輸入圖片說明

我將源代碼文件作為 test.html 保存到我的驅動器中並打開它並單擊帶有以下代碼的項目框。 只需編輯本地計算機的路徑即可。

from selenium import webdriver
import time

driver = webdriver.Firefox(executable_path=r'C:\\Path\\To\\geckodriver.exe')

driver.get("file:///C:/Path/To/test.html")

time.sleep(1)
#project = driver.find_element_by_xpath("//select[@id='edit-projects']")
#project.click()

project_elements = driver.find_elements_by_xpath("//select[@id='edit-projects']")
for element in project_elements:
    try:
        element.click()
    except Exception as e:
        print(e)

暫無
暫無

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

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