1.screenshot全屏截图

  1. # coding=utf-8
  2. from selenium import webdriver
  3. import time
  4. from config import setting
  5. driver = webdriver.Chrome(r'C:\Users\86185\Desktop\DemoUI\driver\chromedriver.exe')
  6. driver.get("https://www.baidu.com")
  7. driver.maximize_window()
  8. time.sleep(2)
  9. picture_time = time.strftime("%Y-%m-%d-%H_%M_%S", time.localtime(time.time()))
  10. print(picture_time)
  11. try:
  12. picturePath=driver.get_screenshot_as_file(setting.TEST_REPORT+'\\screenshot\\'+ picture_time +'.png')
  13. print("%s:截图成功!!!" % picturePath) #图片地址——绝对路径
  14. except BaseException as msg:
  15. print(msg)
  16. driver.quit()