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()