0
我已经创建了一个python脚本,用于在浏览器上执行一些操作并截取它。 当系统没有锁定我的脚本工作正常。 但是当系统被锁定时,它会截取我锁定的屏幕而不是浏览器。 如何在系统锁定时拍摄浏览器截图?当系统处于锁定状态时以python截图
我使用:
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium import webdriver
import time
from selenium.webdriver.chrome.options import Options
from PIL import ImageGrab
import win32com.client as win32
import re
options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")
driver = webdriver.Chrome(chrome_options=options)
chromedriver = 'C:\Python27\chromedriver_win32\chromedriver.exe'
driver = webdriver.Chrome(chromedriver)
link=driver.get('http://10.113.174.197/testlink/login.php?
note=logout&viewer=')
username = "xyz"
password = "xyz"
def login():
inputid = driver.find_element_by_id('tl_login')
inputid.send_keys(username)
inputpass = driver.find_element_by_name('tl_password')
inputpass.send_keys(password)
signin = driver.find_element_by_xpath('//*[@id="login"]/div[3]/input')
signin.click()
time.sleep(3)
def testreport():
driver.get("http://10.113.174.197/testlink/lib/results/resultsByTesterPerBuild.php?format=0&tplan_id=537")
#driver.get('http://10.113.174.194/testlink/lib/results/resultsGeneral.php?format=0&tplan_id=125194')
def screenshot():
img = ImageGrab.grab()
img.save('C:\Users\XYZ\Downloads\screenshot.png')
img.show()
def mail():
outlook = win32.Dispatch('outlook.application')
mail = outlook.CreateItem(0)
mail.To = '[email protected]'
mail.Subject = 'xyz '
attachment =mail.Attachments.Add("C:\Users\XYZ\Downloads\screenshot.png")
mail.Attachments.Add('C:\Users\MA299445\Downloads\screenshot.png')
mail.Send()
if __name__ == '__main__':
login()
testreport()
time.sleep(3)
screenshot()
time.sleep(3)
mail()
环境: 的Python 2.3 的Windows 10
给你的完整代码或这是它? –
@manan_kalariya:我已经添加了我的完整代码,请检查。 –