簡體   English   中英

如何通過 python 中的 selenium 對列表框中的元素進行 select

[英]How to select an element in list box by selenium in python

我是 python 的新手。 我想 select 列表框中的一個元素。 我知道這是一項簡單的任務,但我不知道為什么它不能在我的計算機上運行。 URL 是:

https://biruni.tuik.gov.tr/disticaretapp/menu_ing.zul

如何使用 select 選擇其中之一?

from selenium import webdriver
from selenium.webdriver.common.by import By
import time
from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome('C:\Webdriver\chromedriver.exe')
driver.get('https://biruni.tuik.gov.tr/disticaretapp/menu_ing.zul')
time.sleep(2)

我通過以下方式嘗試了很多 select:

select.select_by_visible_text("Partner country/ Country Groups")

或者

driver.find_element(By.XPATH,'//*[@id="yXAPg2-cave"]').click()

但它不起作用? 我不知道為什么! 你能幫幫我嗎?

您可以通過在其包含的文本上選擇元素來單擊所需的元素。 以下代碼應該可以正常工作。

element = driver.find_element(by=By.XPATH,value='//*[contains(text(), "Partner country/ Country Groups")]')                                                                                                            
element.click()

暫無
暫無

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

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