Reputation: 189
I am able to load a chrome extension called Desktopify through a CRX file and successfully add it to the chrome with selenium webdriver using C# with Chrome Options. I have 2 questions.
Can anyone tell me how to automate to click the extension once it added to chrome? Every time I have to click manually on the extension for the further process of automation.
After the extension is loaded into the ChromeDriver, how can I interact with the elements in the extension?
This is what I've tried so far just for question #1 ...
ChromeOptions options = new ChromeOptions();
options.AddExtension(@"D:\Downloads\Desktopify\nlhjgcligpbnjphflfdbmabbmjidnmek.crx");
options.AddArgument("test-type");
System.Environment.SetEnvironmentVariable("webdriver.chrome.driver", @"D:\VisualStudioExpress2017\Projects\MyApp\bin\Debug\chromedriver.exe");
driver = new ChromeDriver(options);
Upvotes: 1
Views: 3481
Reputation: 1868
For clicking on the extension icon you can use this:
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("window.postMessage('clicked_browser_action', '*')");
For working with the extension elements, you should switch to frame (you can see on DOM, that the extension is a frame with some id)
driver.SwitchTo().Frame(driver.FindElement(By.id("your_frame_Id")));
Upvotes: 0