【发布时间】:2021-02-05 06:42:30
【问题描述】:
网址:https://vahan.parivahan.gov.in/vahan4dashboard/vahan/view/reportview.xhtml'
我正在尝试使用 selenium 从该网站下载数据,但它的设置方式令人困惑。我需要弄清楚如何使用名为“Y-Axis”的列表中的下拉菜单并从该列表中选择“Maker”。然后我需要点击“刷新”按钮和“下载 excel”按钮。这是下拉菜单的html:
<select id="yaxisVar_input" name="yaxisVar_input" tabindex="-1" aria-hidden="true" onchange="PrimeFaces.ab({s:"yaxisVar",e:"change",f:"masterLayout_formlogin",p:"yaxisVar",u:"xaxisVar"});"><option value="Vehicle Category" data-escape="true">Vehicle Category</option><option value="Vehicle Class" selected="selected" data-escape="true">Vehicle Class</option><option value="Norms" data-escape="true">Norms</option><option value="Fuel" data-escape="true">Fuel</option><option value="Maker" data-escape="true">Maker</option></select>
这是我正在玩的代码:
从硒导入网络驱动程序
from selenium.webdriver.support.ui import Select
driver = webdriver.Chrome('C:/Users/abhay.singh/chromedriver')
driver.get('https://vahan.parivahan.gov.in/vahan4dashboard/vahan/view/reportview.xhtml')
# Get the y-axis selector
# select = Select(driver.find_element_by_id('yaxisVar_input'))
# select.select_by_visible_text('Maker').click()
# print(select.options)
# print([o.text for o in select.options])
driver.find_element_by_xpath("//select[@name='yaxisVar_input']/option[text()='Maker']").click()
感谢您帮助解决这个问题!
【问题讨论】:
标签: python-3.x selenium selenium-webdriver