无法从下拉列表中找到项目

2024-09-27 19:22:10 发布

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

我无法从列表中选择“Wiley”

Screenshot of HTML

driver = webdriver.Chrome(executable_path=r"D:\Python\Lib\site-packages\selenium\chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 10)
driver.get('https://www.webofknowledge.com/')
wait.until(EC.visibility_of_element_located((By.XPATH, "//*[@id='select2-shibSelect-container']"))).click()

Tags: ofpath列表libpackageshtmldriverselenium
2条回答

您可以使用selenium Select类来选择选项。详情here

from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome()
driver.maximize_window()
wait = WebDriverWait(driver, 10)
driver.get('https://www.webofknowledge.com/')
select = Select(driver.find_element_by_id('shibSelect'))
select.select_by_visible_text('AirLiquide')
driver.find_element_by_id('shibSubmit').click()

备选案文1:

from selenium import webdriver
from chromedriver_py import binary_path
from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome(executable_path=binary_path)
driver.get('https://www.webofknowledge.com/')
select = Select(driver.find_element_by_id('shibSelect'))
select.select_by_visible_text('Wiley')
driver.find_element_by_id('shibSubmit').click()

备选案文2:

from selenium import webdriver
from chromedriver_py import binary_path

url = "http://www.webofknowledge.com/?auth=ShibbolethIdPForm&target=https%253A%252F%252Fwww.webofknowledge.com%252F%253FIsProductCode%253DYes%2526Error%253DIPError%2526PathInfo%253D%25252F%2526RouterURL%253Dhttps%25253A%25252F%25252Fwww.webofknowledge.com%25252F%2526Domain%253D.webofknowledge.com%2526Src%253DIP%2526Alias%253DWOK5%2526ShibFederation%253DWileyVCH&entityID=https://sts.windows.net/24fe244f-890e-46ef-be2f-a5202976b7a5/&return=https%3A%2F%2Fwww.webofknowledge.com%2F%3Fauth%3DShibbolethIdPForm%26target%3Dhttps%25253A%25252F%25252Fwww.webofknowledge.com%25252F%25253FIsProductCode%25253DYes%252526Error%25253DIPError%252526PathInfo%25253D%2525252F%252526RouterURL%25253Dhttps%2525253A%2525252F%2525252Fwww.webofknowledge.com%2525252F%252526Domain%25253D.webofknowledge.com%252526Src%25253DIP%252526Alias%25253DWOK5%252526ShibFederation%25253DWileyVCH"
driver = webdriver.Chrome(executable_path=binary_path)
driver.get(url)

相关问题 更多 >

    热门问题