#################################
总结: 1,元素的定位
2,元素的操作
元素的,大小,文本,当前页面的连接,当前页面的title,获取元素的属性值,
鼠标操作,单选context_click,多选double_click,拖拽drag_and_drop,悬停move_to_element(), perform()
键盘操作,send_keys()
警告框操作 text,accept,dismiss,
窗口操作,switch_to.
下拉框操作 by_css_selector().click() select = select(ele) by_index, by_value by_vistable_text()
iframe操作
截图操作 get_shortcreen_to_file()
webdriver的操作,driver=webdriver.Firefox(),driver.get ,sendkeys, click, close quit,
窗口操作,最大化,
执行js,execute_script
隐式等待,impi
3,unittest框架的使用
测试用例
测试套件,
测试执行,
fix,两个函数,
断言,
报表,HTMLTestRunner
###########################
主要是定位和操作
driver = webdriver.Firefox()
driver.get("url")
driver.find_element_by_id()
driver.find_element_by_name()
driver.find_element_by_class_name()
driver.find_element_by_tag_name
driver.find_element_by_link_text(
driver.find_element_by_partial_link_text(
driver.find_elements_by_css_selector()
driver.maximize_window()
send_keys()
click()
close() 关闭单个窗口,
quit() 关闭所有的窗口,
##########################
获取元素信息的操作: size text title current_url get_attribute('XXX') eg href is_display() is_enabled() context_click() double_click() drag_and_drop() move_to_element() perform()执行上面的操作, sendkeys(keys.BACK_SPACE) driver.implicitly_wait(10) selectEle = driver.find_elements_by_css_selector('select') select = Select(selectEle) select.select_by_index(1) select.select_by_value('sh') select.select_by_visible_text('上海')
####################################
alert = driver.switch_to.alert #切换到警告框上, text = alert.text # 需要一个变量接收 alert.accept() alert.dismiss() driver.execute_script(js1) driver.switch_to.frame('name') driver.switch_to.default_content() driver.switch_to.window(hanle) river.get_screenshot_as_file('../img/123.png') get_cookie(name) get_cookie() add_cookie(str)
#############################
class Test01(unittest.TestCase): suite = unittest.Testsuite() suite = unittest.defaultTestLoader.discover("./",pattern="test*.py") runner = unittest.TextTestRunner() runner.run(suite) def setUp(self): def tearDown(self): 1,assertEqual(arg1,arg2) ,assertIn(arg1,arg2) ,assertTrue('xx' in msg)
############################
##############################