• Selenium_单选框和复选框的选中状态判定以及元素是否可用和可见判定(10)


     简单写个单选框和复选框界面

    <!DOCTYPE html>
    <html>
    
    <head>
        <meta charset="utf-8" />
        <title>test</title>
        
    </head>
    
    <body bgcolor="burlywood">
        <form>
            <input type="radio" name="sex" value="male">Male<br>
            <input type="radio" name="sex" value="female">Female<br>
            <input type="checkbox" name="vehicle" value="Bike">I have a bike<br>
        </form>
        
    </body>
    
    </html>

    界面效果如下

    相关脚本代码如下

    import time
    from selenium import webdriver
    from selenium.webdriver import ActionChains
    
    driver = webdriver.Chrome()
    driver.maximize_window()
    driver.get("file:///D:/Users/User/Desktop/test.html")
    
    # 检查单选框是否被选择
    radios = driver.find_elements_by_xpath("//*[@type='radio']")
    radio1 = radios[0]
    radio2 = radios[1]
    radio1.click()
    # 检查单选框是否被选中,选中返回True
    print(radio1.is_selected())
    radio2.click()
    print(radio1.is_selected())
    time.sleep(2)
    
    # 检查复选框是否被勾选
    checkbox = driver.find_element_by_xpath("//*[@type='checkbox']")
    checkbox.click()
    print(checkbox.is_selected())
    time.sleep(2)
    checkbox.click()
    print(checkbox.is_selected())
    
    # 检查元素是否可用,可用返回True
    print(checkbox.is_enabled())
    
    # 检查元素是否显示,显示返回True
    print(checkbox.is_displayed())
  • 相关阅读:
    MySQL数据库有哪些安全相关的参数需要修改?
    Python PEP-8编码风格指南中文版
    linux系统/var/log目录下的信息详解
    mcelog用法详解
    timeout 命令
    x86服务器MCE(Machine Check Exception)问题
    IPv6简介
    MySQL innodb统计信息
    memory 监控 mysql vs percona vs maria
    oracle 压力测试工具benchmarksql
  • 原文地址:https://www.cnblogs.com/testlearn/p/14379816.html
Copyright © 2020-2023  润新知