None

生命就像一条蜿蜒的河流

导航

selenium学习笔记06-CheckBox和radiobutton的定位技巧

from selenium import webdriver
from time import sleep
import os
class TestCase(object):
    def __init__(self):
        self.driver = webdriver.Chrome()
        path = os.path.dirname(os.path.abspath(__file__))
        file_path = 'file:///'+path +'/forms2.html'
        self.driver.get(file_path)

    def test_checkbox(self):
        swimming = self.driver.find_element_by_name('swimming')
        if not swimming.is_selected(): #被选中
            swimming.click()
        reading = self.driver.find_element_by_name('reading')
        if not reading.is_selected():
            reading.click()
        sleep(3)
        swimming.click()
        sleep(5)
        self.driver.quit()

    def test_radio(self): #radio具有排他性
        lst = self.driver.find_elements_by_name('gender')
        # lst[0].click()
        lst[1].click()


if __name__ == '__main__':
    case = TestCase()
    # case.test_checkbox()
    case.test_radio()

 

posted on 2021-02-25 17:07  我睡着了  阅读(169)  评论(0编辑  收藏  举报