selenium代码 进阶 (3)

1.写一个测试用例   新建类,继承unittest.TestCase  -》导包-》写test方法
1 class TestCase(unittest.TestCase) //  1. 新建类继承unittest.TestCase 2导入uniitest
2         def test_01_login(self):  //3. 写test方法
3           driver = webdriver.Chrome()
4           driver.get("https://www.baidu.com/")
5           elem = driver.find_element(By.XPATH, "/html/body/div[1]/div[2]/div[2]/a[1]").click()
6         

2.单元测试的坑  如果想要执行一个指定的单元方法,使用unittest for TestCase环境, 

  命令行方式: python -m unittest  test_case.py  执行 其中所有的测试方法

        python -m unittest  test_case.类名.待执行方法名        执行指定的测试方法

 --------执行main()方法:需要配置环境,同时会全部执行测试方法

 

3.进入Frame框架

driver.switch_to.frame("框架的名称")  //进框架
driver.switch_to.defaule_content() //出框架


//选中下拉菜单所有分类
elem =  driver.find_element(By.NAME,"")   //先定位  下拉菜单
sel= Select(elem) //转换成 Select

sel.select_by_value() //通过值选中

 

    

posted @ 2022-10-12 10:35  晒太阳m  阅读(39)  评论(0)    收藏  举报