4

我使用Selenium網絡驅動程序開發使用Chrome作爲瀏覽器的自動化測試。我爲此使用Python。如何選擇使用Selenium時啓用的Chrome擴展程序

我在Chrome瀏覽器上有一個擴展,我希望在Selenium打開Chrome時啓用它。問題是,當Selenium打開Chrome瀏覽器時,默認情況下禁用所有擴展。

Selenium運行時,如何在Chrome瀏覽器中啓用全部或特定擴展程序?

回答

4

您可以使用ChromeOptions類或DesiredCapabilities來完成此操作。爲此,您必須具有.crx文件並將其加載到驅動程序實例中。從@alecxe答案採取有關ChromeOptions here和更多的細節和DesiredCapabilities here

+0

import os from selenium import webdriver from selenium.webdriver.chrome.options import Options executable_path = "path_to_webdriver" os.environ["webdriver.chrome.driver"] = executable_path chrome_options = Options() chrome_options.add_extension('path_to_extension') driver = webdriver.Chrome(executable_path=executable_path, chrome_options=chrome_options) driver.get("http://stackoverflow.com") driver.quit() 

代碼這個工作!非常感謝你......我還有一個額外的問題。我現在如何改變這個擴展中的選項?例如。該擴展需要鞋號,並且需要在其自己的用戶界面中啓用。 – SkyBlue

相關問題