selenium學習筆記05-selenium操作from表單


from表單的流程:

1、定位表單元素

2、輸入測試值

3、判斷表單元素屬性

4、獲得表單元素屬性

5、提交表單進行驗證

 

from selenium import webdriver
import os
from time import sleep


class TestCase(object):
    def __init__(self):
        self.driver = webdriver.Chrome()
        #自定義表單
        path = os.path.dirname(os.path.abspath(__file__))
        file_path = 'file:///' + path + '/forms.html'
        self.driver.get(file_path)

    def test_login(self):
        username = self.driver.find_element_by_id('username')
        username.send_keys('admin')
        pwd = self.driver.find_element_by_id('pwd')
        pwd.send_keys('123')

        print(username.get_attribute('value'))
        print(pwd.get_attribute('value'))


        self.driver.find_element_by_id('submit').click()
        self.driver.switch_to.alert.accept()
        sleep(2)

        username.clear()
        pwd.clear()

        sleep(2)


if __name__ == '__main__':
    case = TestCase()
    case.test_login()

 


免責聲明!

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



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