25. 常见元素定位 - radio

2024-03-10  本文已影响0人  薛东弗斯

1. radio定位

单选框 - View Design (iviewui.com)

image.png
## 根据下标定位
import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://iviewui.com/view-ui-plus/component/form/radio')
driver.find_elements(By.XPATH,'//input[@class="ivu-radio-input" and @type="radio"]')[0].click()
time.sleep(3)
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()
time.sleep(3)
driver.close()
image.png
# 根据文本进行定位
import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://iviewui.com/view-ui-plus/component/form/radio')
driver.find_elements(By.XPATH,'//span[text()="Android"]')[0].click()
time.sleep(3)
driver.find_elements(By.XPATH,'//span[text()="Windows"]')[0].click()
time.sleep(3)
driver.close()
import time
from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://iviewui.com/view-ui-plus/component/form/radio')

# 根据同级的哥哥、input子标签进行定位
driver.find_elements(By.XPATH,'//span[text()="Android"]/preceding-sibling::span/input')[1].click()
time.sleep(3)
driver.close()
上一篇下一篇

猜你喜欢

热点阅读