美文网首页
25. 常见元素定位 - radio

25. 常见元素定位 - radio

作者: 薛东弗斯 | 来源:发表于2024-03-10 04:59 被阅读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()
    

    相关文章

      网友评论

          本文标题:25. 常见元素定位 - radio

          本文链接:https://www.haomeiwen.com/subject/gywyzdtx.html