[英]Selenium:How to open chrome extension with selenium/or login to chrome extension
任務:模擬通過 selenium 登錄到 chrome 擴展。
讓我們使用任何需要登錄的擴展名。 我們可以將它添加到 selenium 測試中,例如使用下面的代碼:
System.setProperty("webdriver.chrome.driver", System.getProperty("path to user dir") + "path to chrome driver exe");
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(System.getProperty("path to user dir") + "path to extension crx file"));
driver = new ChromeDriver(options);
但是有一個麻煩 - 我們應該登錄到這個擴展,繼續工作。 (例如任何加密錢包,例如 jpg 上的 iostwallet)
那么,如何使用 selenium 方法按下擴展按鈕並輸入憑據?
我在@amy 博客的建議中找到了答案。 謝了哥們!
簡而言之,我們可以通過以下方式進行:
1)查看所需擴展的來源:
- download crx of needed extension
- get extension unique ID (just on extension page in "details")
- view it source, eg using "extension source viewer" extension
- note page You need (e.g. "index.html")
2)現在我們有我們需要來源的頁面的 url,例如
chrome-extension://<extension unique ID>/index.html
我們可以使用 selenium 在頁面上輕松導航,例如
driver.get(config.getProperty("extensionpageurl"));
driver.findelement(....).<actions>;
...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.