2017-09-20 5 views
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

+0

完全なコードを入力してください。これはそれですか? –

+0

@manan_kalariya:完全なコードを追加しました。 –

答えて

0

をあなたはスクリーンショットをキャプチャするためにセレンを使用することができます。画面がロックされていても動作します。

from selenium import webdriver 
import os 
driver = webdriver.Chrome("C:\Python27\Scripts\chromedriver.exe") 
#removes the file if it already exists 
try: 
    os.remove('E:\dhd.png') 
except WindowsError: 
    #print("no file found") 
    pass 
# Maximize the browser window 
driver.maximize_window() 
driver.get("https://accounts.google.com/ServiceLogin/identifier?service=mail&passive=true&rm=false&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&ss=1&scc=1&ltmpl=default&ltmplcache=2&emr=1&osid=1&flowName=GlifWebSignIn&flowEntry=AddSession") 
driver.save_screenshot('e:\dhd.png') 
driver.quit() 
関連する問題