Selenium WebDriver-操作頁面下拉列表


#encoding=utf-8
import unittest
import time
import chardet
from selenium import webdriver
 
class VisitSogouByIE(unittest.TestCase):

    def setUp(self):
        #啟動IE瀏覽器
        #self.driver = webdriver.Firefox(executable_path = "e:\\geckodriver")
        self.driver = webdriver.Ie(executable_path = "e:\\IEDriverServer")
        
    def test_printSelectText(self):
        url = "http://127.0.0.1/test_select.html"
        # 訪問自定義的html網頁
        self.driver.get(url)
        # 使用name屬性找到頁面上name屬性為“fruit”的下拉列表元素
        select = self.driver.find_element_by_name("fruit")
        all_options = select.find_elements_by_tag_name("option")
        for option in all_options:
            print u"選項顯示的文本:", option.text
            print u"選項值為:", option.get_attribute("value")
            option.click()
            time.sleep(1)

       



    def tearDown(self):
        # 退出IE瀏覽器
        self.driver.quit()

if __name__ == '__main__':
    unittest.main()

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM