我正在尝试选择this website上的“CAS Number”选项。通过阅读其他文章,我已经使用Selenium编写了几个Python代码
driver.find_element_by_css_selector("select#selectbox > option[value='cas']").click()
driver.find_element_by_xpath("//select[@id ='selectbox']/option[@value ='cas']").click()
box = driver.find_element_by_id('selectbox')
for option in box.find_elements_by_tag_name('option'):
if option.text == 'cas':
option.select()
但他们都没有选择合适的盒子。所以我想知道问题出在哪里。
在检查了那个网站的DOM之后,
<select id="selectbox" name="focus" style="display: none;">
不是人们在UI中看到的那个。实际下拉菜单是:
因此,请尝试以下代码:
首先单击
input
,然后单击所需的列表项。例如,对于CAS Number
:注意,它不是一个常规的} 可以更容易地操作
select
标记,使用^{相关问题 更多 >
编程相关推荐