zoukankan      html  css  js  c++  java
  • python+webdriver(三)

    #截图功能

    #-*-coding=utf-8
    from selenium import webdriver
    from selenium.common.exceptions import NoSuchElementException
    import unittest
    import time
     
    class login(unittest.TestCase):
        def setUp(self):
            self.driver = webdriver.Firefox()
            self.driver.implicitly_wait(10)
            self.base_url = "http://www.baidu.com"
            self.verificationErrors = []
        
        def test_loginpass(self):
            driver = self.driver
            driver.get(self.base_url)
            driver.find_element_by_link_text("搜索设置").click()
            driver.find_element_by_id("s1_2").click()
            m=driver.find_element_by_name("NR")
            try:
                m.find_element_by_xpath("//option[@value='1000']").click()
            except:
                driver.get_screenshot_as_file("D:/screenshots/dd.png")#如果没有找到上面的元素就截取当前页面。
                time.sleep(5)
            driver.find_element_by_xpath("//input[@value='保存设置']").click()
            driver.switch_to_alert().accept()
        def tearDown(self):
            #self.driver.quit()
            self.assertEqual([], self.verificationErrors)
            
    if __name__ == "__main__":
        unittest.main()
    python webdriver 截图函数为get_screenshot_as_file(filename)
     
    也可以事先定义好文件名和路径
  • 相关阅读:
    BZOJ5311,CF321E 贞鱼
    POJ3208 Apocalypse Someday
    POJ1037 A decorative fence
    POJ1737 Connected Graph
    CF559C Gerald and Giant Chess
    NOI2009 诗人小G
    Problem 2726. -- [SDOI2012]任务安排
    POJ1821 Fence
    HDU5542 The Battle of Chibi
    POJ2376 Cleaning Shifts
  • 原文地址:https://www.cnblogs.com/draycen/p/3167336.html
Copyright © 2011-2022 走看看