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:我已經添加了我的完整代碼,請檢查。 –