Selenium_Webdriver–Chrome驱动测试

1.Chrome Webdriver testing.
Q:在执行selenium/webdriver 的测试用例的时候,默认是驱动FireFox()浏览器进行测试的, 如果我尝试用Chrome 去驱动测试呢?
A:首先下载Chrome webdriver(os-Win10 64 bit):
点击这里,下载Chrome Webdriver.
然后解压到对应的位置,在代码中替换“self.driver = webdriver.Firefox()”为:
self.driver = webdriver.Chrome(executable_path=
“C:/Users/JANE/Documents/Webdriver/chromedriver”)
解决啦!

2.屏幕截图.
Tips:在测试的过程中,想要看到用例执行的过程实际屏幕是什么样子的,可以选用截图操作:
driver = self.driver
driver.save_screenshot(‘checkbox.png’)

3.上传文件操作.
selenium2.x webdriver 测试的上传文件功能特别简单,不需要点击页面中的按钮,选择本地文件等操作,只要一个send_keys()!
driver.find_element(by_id, by_name,etc).send_keys(“thepathoflocalfile”)
eg:driver.find_element_by_name(“file”).send_keys
(“D:\ABA_Selenium_Testing\ABATesting\checkbox.png”)

参考文章:
https://jzchangmark.wordpress.com/2015/02/26/selenium-%E4%BD%BF%E7%94%A8-chrome-%E7%80%8F%E8%A6%BD%E5%99%A8-webdriver/
http://www.weiguda.com/blog/47/

Love python! A little change everyday…

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.