昆明网站设计电话,建设工程施工合同管理论文,如何通过网站开发客户,百度标记号码认证平台P155——创建测试用例录制脚本编辑脚本定位辅助P159——Selenium IDE 命令在浏览器中打开URL#xff0c;可以接受相对路径和绝对路径两种形式openopen(url)单击链接、按钮、复选框和单选框click(elementLocator)模拟键盘的输入#xff0c;向指定的input中输入值type(inputLoc…P155——创建测试用例 录制脚本编辑脚本定位辅助 P159——Selenium IDE 命令 在浏览器中打开URL可以接受相对路径和绝对路径两种形式 open open(url) 单击链接、按钮、复选框和单选框 click(elementLocator) 模拟键盘的输入向指定的input中输入值 type(inputLocator,value) 根据optionSpecifier选项选择器来选择一个下拉菜单选项 select(dropDownLocator,optionSpecifier) 模拟单击浏览器的后退按钮 goBack() 选择一个弹出窗口 select(windowId) 根据指定时间暂停Selenium脚本执行 pause(millisenconds) 模拟页面元素事件被激活的处理动作 fireEvent(elementLocatore,evenName) 模拟单击浏览器关闭按钮 close P162——断言与验证 P167——等待与变量 1、启用火狐插件Selenium IDE 2、点击红点进行脚本录制 3、使用Selenium IDE导出脚本选择导出Python语言的脚本 4、在命令行中运行该脚本报错。这是因为Python文件在第10行没有类名导致 5、导出脚本的源码如下添加一个hello类名再运行 # -*- coding: utf-8 -*- from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support.ui import Select from selenium.common.exceptions import NoSuchElementException from selenium.common.exceptions import NoAlertPresentException import unittest, time, re class hello(unittest.TestCase): def setUp(self): self.driver webdriver.Firefox() self.driver.implicitly_wait(30) self.base_url https://www.baidu.com/ self.verificationErrors [] self.accept_next_alert True def test_(self): driver self.driver driver.get(self.base_url /) driver.find_element_by_id(kw).click() driver.find_element_by_id(kw).clear() driver.find_element_by_id(kw).send_keys(u你好) driver.find_element_by_id(su).click() def is_element_present(self, how, what): try: self.driver.find_element(byhow, valuewhat) except NoSuchElementException as e: return False return True def is_alert_present(self): try: self.driver.switch_to_alert() except NoAlertPresentException as e: return False return True def close_alert_and_get_its_text(self): try: alert self.driver.switch_to_alert() alert_text alert.text if self.accept_next_alert: alert.accept() else: alert.dismiss() return alert_text finally: self.accept_next_alert True def tearDown(self): self.driver.quit() self.assertEqual([], self.verificationErrors) if __name__ __main__: unittest.main() 运行成功 转载于:https://www.cnblogs.com/TomBombadil/p/10977809.html