我已经编写了以下脚本来截取屏幕截图。目前,它将文件保存在python文件所在的目录中。我想将屏幕截图保存在特定的文件夹中。
from selenium import webdriver
import option
import time
#PhantomJS
driver = webdriver.PhantomJS(executable_path=r'D:\PhantomJS\phantomjs-2.1.1-
windows\bin\phantomjs.exe')
#Selenium
#driver = webdriver.Chrome("D:\Selenium\Chrome\chromedriver.exe")
#Maximizes window to full screen
driver.maximize_window()
#Gets the URL for OMS
driver.get(option.OMS_QUERY)
#Gets the username & Password
driver.find_element_by_xpath(option.LOG_IN).click()
driver.find_element_by_id("username").send_keys(option.USERNAME)
driver.find_element_by_xpath(option.ENTER).click()
time.sleep(3)
driver.find_element_by_id("password").send_keys(option.PASSWORD)
driver.find_element_by_xpath(option.ENTER).click()
time.sleep(15)
#Saves the screenshot for OMS_SWR
driver.save_screenshot('oms_swr.png')
#Gets the URL for DMS
driver.get(option.DMS_QUERY)
time.sleep(15)
#Saves the screenshot for DMS_SWR
driver.save_screenshot('dms_swr.png')
driver.quit()
答案 0 :(得分:0)
要将 screenshot
保存在特定文件夹中,您可以使用以下任一选项:
在您的项目空间内:
driver.save_screenshot('./project_directory/save_screenshot.png')
在您的系统中:
driver.save_screenshot('C:/system_directory/save_screenshot.png')
答案 1 :(得分:0)
您必须设置要存储它的路径,像这样存储在系统驱动器中
driver.save_screenshot('D:/Folder_name/dms_swr.png')
答案 2 :(得分:-1)
在我的情况下,这种方式有帮助 - browser.save_screenshot('D:/Folder_name/dms_swr.png')