如果出现下面这种多个下拉框,但并不是每个下拉框都有自己的固定id,name时,我们可以用class_name或者tag_name选择符合条件的所有页面元素,然后根据下标来选择第几个

from selenium.webdriver.support.select import Select
#选择收货人所在省份
province = driver.find_element_by_id("add-new-area-select")
Select(province).select_by_visible_text("山西省")
#选择收货地区市
city = driver.find_elements_by_class_name("add-new-area-select")[1]
Select(city).select_by_visible_text("大同市")
#选择收货地区
stats = driver.find_elements_by_tag_name("select")[2]
Select(stats).select_by_visible_text("市辖区")
自动化选择网页下拉框实例: Selenium实践
596

被折叠的 条评论
为什么被折叠?



