zoukankan      html  css  js  c++  java
  • selenium学习笔记07-selenium操作下拉表单

    selenium操作下拉表单

    from selenium import webdriver
    from time import sleep
    import os
    
    from selenium.webdriver.support.select import Select
    
    
    class TestCase(object):
        def __init__(self):
            self.driver = webdriver.Chrome()
            path = os.path.dirname(os.path.abspath(__file__))
            file_path = 'file:///' + path + '/form3.html'
            self.driver.get(file_path)
    
        def test_select(self):
            se = self.driver.find_element_by_id('provise')
            select= Select(se)
    
            # select.select_by_index(2) #根据索引选择
            #
            # sleep(2)
            #
            # select.select_by_value('bj') #根据值选择
            #
            # sleep(2)
            #
            # select.select_by_visible_text('Tianjin') #根据文本选择
            #
            # sleep(2)
    
            # for i in range(3): 都选
            #     select.select_by_index(i)
            #     sleep(1)
            # sleep(3)
            #
            # select.deselect_all() 反选所有
            #
            # sleep(3)
    
            for option in select.options: #所有选项
                print(option.text)
    
            self.driver.quit()
    
    
    if __name__ == '__main__':
        case = TestCase()
        case.test_select()
     
  • 相关阅读:
    阿牛的EOF牛肉串
    盐水的故事
    密码
    Digital Roots
    不容易系列之(3)—— LELE的RPG难题
    不容易系列之一
    超级楼梯
    母牛的故事
    蟠桃记
    Children’s Queue
  • 原文地址:https://www.cnblogs.com/yronl/p/14448112.html
Copyright © 2011-2022 走看看