import time from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.support.select import Select driver = webdriver.Edge() driver.get("file:///D:\本地练习网页.html") # 创建一个select对象 select_element = driver.find_element(By.ID, "s4Id") select_multiple_object = Select(select_element) time.sleep(3) # 有三种方式可以选择选项 # 通过选项索引 # select_object.select_by_index(2) # 通过选项value属性值 # select_object.select_by_value('o3') # 通过选项文本 # select_object.select_by_visible_text('o1') select_multiple_object.select_by_index(1) select_multiple_object.select_by_value('o3val') time.sleep(2) # 确定是否允许多选,,选项.is_multiple代表是否可以被多选 # does_this_allow_mutiple_selections = select_multiple_object.is_multiple # print("----是否允许多选----------") # print(does_this_allow_mutiple_selections) # 反选:通过索引 # select_multiple_object.deselect_by_index(1) # time.sleep(2) # # 反选:通过value值 # select_multiple_object.deselect_by_value('o3val') # 反选:通过选择文本 # select_multiple_object.deselect_by_visible_text('o3') # 取消所有被选择的选项 select_multiple_object.deselect_all()
标签:选项,WEB,multiple,object,value,复选框,自动化,import,select From: https://www.cnblogs.com/gezirui/p/17573783.html