如何在python中使用selenium从下拉列表中选择选项

2024-05-23 14:50:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从下面的列表中选择一个使用selenium的选项:

HERE

但问题是没有可供选择的列表

enter image description here

到目前为止,我的代码是:

from seleniumwire import webdriver 
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
 
chrome_options = Options()
#chrome_options.add_argument("--headless")
# for linux/Ubuntu only
#chrome_options.add_argument("--no-sandbox") 


browser = webdriver.Chrome(ChromeDriverManager().install(), 
  chrome_options=chrome_options)
browser.get('https://www.ibm.com/demos/live/tts-demo/self-service/home')
#element = browser.find_element_by_id('downshift-2-toggle-button').click()
#select_voice = Select(element)
voice= browser.find_element_by_xpath('//*[@id="downshift-2-toggle- 
 button"]/span')
browser.execute_script('arguments[0].innerHTML = "Michael";', voice)

需要帮助


Tags: fromimportbrowseradd列表seleniumelementfind
1条回答
网友
1楼 · 发布于 2024-05-23 14:50:39

要查找元素Michael,请单击神经音域,然后单击带有Michael文本的标记

voice = browser.find_element_by_xpath("//*[@id='downshift-2-toggle-button']/span")
voice.click()
browser.find_element_by_xpath("//div[.='Michael']").click()

enter image description here

相关问题 更多 >