follow yoyo
定位下拉列表并选取内容
# coding:utf-8from selenium import webdriverfrom selenium.webdriver.common.action_chains import ActionChainsfrom selenium .webdriver.support.select import Select driver = webdriver.Firefox()driver.get("https://baidu.com")driver.implicitly_wait(20) # 鼠标移动到设置按钮mouse = driver.find_element_by_link_text("设置")ActionChains(driver).move_to_element(mouse).perform()driver.find_element_by_link_text("搜索设置").click() # 方法一:定位到下拉框,再点击选项# s = driver.find_element_by_id("nr")# s.find_element_by_xpath("//option[@value=‘50‘]").click()driver.find_element_by_id("nr").find_elements_by_xpath("//option[@value=‘50‘]").clear() # 方法二:使用xpath/css定位driver.find_elements_by_xpath("//*[@id=‘nr‘]/option[2]").click() # 方法三:使用Select模块by indexs = driver.find_element_by_id("nr")Select(s).select_by_index(2) # select by valueSelect(s).select_by_value("20") # select by textSelect(s).select_by_visible_text("每页显示20条")
原文地址:https://www.cnblogs.com/shanliguniang/p/10654030.html
时间: 2024-11-08 23:57:37