0
在Selenium Webdriver中,我希望能夠使用從Python腳本執行的FireShot進行全屏截圖。Selenium Webdriver:如何使用Python編寫的FireShot進行全屏截圖
我有下面的代碼至今:
import unittest
import execjs
from execjs import get
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
class PythonOrgSearc(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Chrome('/usr/bin/chromedriver');
def test_login_and_make_payment_on_account(self):
driver = self.driver;
driver.set_window_size(1024,768);
# Log in to My Account
driver.get("https://www.mywebsite.com");
self.assertIn("Sign In", driver.title);
driver.save_screenshot('/Users/username/Documents/Selenium_Test/01a_login.png');
# Enter username
user = driver.find_element_by_id("EmailOrAccountNumber");
user.send_keys("[email protected]");
# Enter password and submit form
password = driver.find_element_by_id("Password");
password.send_keys("password123");
driver.save_screenshot('/Users/username/Documents/Selenium_Test/01b_login_filled.png');
password.send_keys(Keys.RETURN);
# Confirm logged into My Account
self.assertIn("Account Summary", driver.title);
driver.save_screenshot('/Users/username/Documents/Selenium_Test/02a_My_Account.png');
def tearDown(self):
self.driver.close();
if __name__ == "__main__":
unittest.main();
我已經安裝了PyExecJS,但不知道我該如何開始使用FireShot的API,以取代在代碼中使用的電流save_screenshot功能。感謝您提供任何指導或指導。
能不能介紹一下爲什麼你認爲driver.execute_script命令展開是更好的,它將如何寫入代碼?看起來我可以這樣做:'driver.execute_script(「http://screenshot-program.com/dloads/fsapi.js」,args)'但是參數應該保存整個頁面的截圖到磁盤? – DigiKev