Python selenium 操作单选框复选框

学习笔记~

from selenium import webdriver
from selenium.webdriver.common import keys
from selenium.webdriver.common.by import By
import time
from selenium.webdriver import ActionChains
from selenium.webdriver.support.select import Select

driver = webdriver.Chrome()

# ===============模拟操作单选框和复选框====================
driver.get(r'D:\00.PythonProject\PyCharmProject\PythonSelenium\checkbox.html')

# 复选框
# # 方式一:
# el1 = driver.find_element(By.XPATH, ".//input[@value='cv1']")
# el1.click()
# # 方式二:
# el2 = driver.find_element(By.XPATH, ".//input[@value='cv2']")
# el2.send_keys(keys.Keys.SPACE)

# 单选框
# 方式一
el3 = driver.find_element(By.XPATH, ".//input[@value='rv1']")
el3.click()

time.sleep(1)
# 方式二
el4 = driver.find_element(By.XPATH, ".//input[@value='rv2']")
el4.send_keys(keys.Keys.SPACE)

a = el4.is_selected()
print(a)

time.sleep(3)

你可能感兴趣的:(Python,python,selenium,开发语言)