zoukankan      html  css  js  c++  java
  • 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())
  • 相关阅读:
    clip属性,截取你想要显示的图片
    select背景灰色
    [转]ShowModal() = mrOk
    【转】Delphi-Unit文件结构
    析构方法
    [转]Delphi 7连接MySql /MariaDB
    MySQL/Mariadb遇见的问题
    更换数据库
    FlameRobin
    FireBird初使用
  • 原文地址:https://www.cnblogs.com/testlearn/p/14379816.html
Copyright © 2011-2022 走看看