7- radio单选框
import time from selenium import webdriver from selenium.webdriver.common.by import By # 定义一个driver的变量,用来接收实例化后的浏览器 # 指定浏览器的位置,解决浏览器驱动和浏览器版本不匹配的问题 chrome_location = r'D:\pythonProject2023\SeleniumFirst\chrome-win64\chrome.exe' options = webdriver.ChromeOptions() options.binary_location = chrome_location driver = webdriver.Chrome(options=options) # 使用get方法,访问网址 driver.get('https://www.iviewui.com/view-ui-plus/component/form/radio') #窗口最大化 driver.maximize_window() #1 找到输入框的位置,输入万笑佛博客园 driver.find_elements(By.XPATH,'//input[@class="ivu-radio-input" and @type="radio"]')[1].click() time.sleep(3) driver.find_elements(By.XPATH,'//input[@class="ivu-radio-input" and @type="radio"]')[2].click() time.sleep(3) driver.find_elements(By.XPATH,'//input[@class="ivu-radio-input" and @type="radio"]')[3].click() driver.find_element(By.XPATH,'//span[text()="Android"]').click() time.sleep(3) driver.quit()
8-select下拉框选择
import time from selenium.webdriver.support.select import Select #pip install selenium from selenium import webdriver from selenium.webdriver.common.by import By # 定义一个driver的变量,用来接收实例化后的浏览器 # 指定浏览器的位置,解决浏览器驱动和浏览器版本不匹配的问题 chrome_location = r'D:\pythonProject2023\SeleniumFirst\chrome-win64\chrome.exe' options = webdriver.ChromeOptions() options.binary_location = chrome_location driver = webdriver.Chrome(options=options) # 使用get方法,访问网址 driver.get("https://sahitest.com/demo/selectTest.htm") #窗口最大化 driver.maximize_window() time.sleep(1) select = Select(driver.find_element(By.ID,'s1')) #根据index下标获取 select.select_by_index(1) #根据value获取 #select.select_by_value("48") #根据看到的内容选择 #select.select_by_visible_text("Cell Phone") time.sleep(3) driver.quit()
9-iframe
import time from selenium.webdriver.support.select import Select #pip install selenium from selenium import webdriver from selenium.webdriver.common.by import By # 定义一个driver的变量,用来接收实例化后的浏览器 # 指定浏览器的位置,解决浏览器驱动和浏览器版本不匹配的问题 chrome_location = r'D:\pythonProject2023\SeleniumFirst\chrome-win64\chrome.exe' options = webdriver.ChromeOptions() options.binary_location = chrome_location driver = webdriver.Chrome(options=options) #窗口最大化 driver.maximize_window() driver.get("https://sahitest.com/demo/iframesTest.htm") driver.find_element(By.ID,"checkRecord").clear() driver.find_element(By.ID,"checkRecord").send_keys("666") time.sleep(3) #用下标 进入iframe driver.switch_to.frame(0) #iframe 如果有id和name 可以用id和name获取 #by ID Name id=iframe_id Name=iframe_name # driver.switch_to.frame("iframe_id") # driver.switch_to.frame("iframe_name") #driver.find_element(By.CSS_SELECTOR,'a[href="linkTest.htm"]').click() driver.find_element(By.ID,'open-self').click() # 退出iframe driver.switch_to.parent_frame() driver.find_element(By.ID,"checkRecord").clear() driver.find_element(By.ID,"checkRecord").send_keys("7777") time.sleep(3) driver.quit()
标签:控件,webdriver,--,driver,下拉框,chrome,find,options,select From: https://www.cnblogs.com/yclh/p/18194524