GRF
GRF

Reputation: 189

How to Click The Chrome Extension in C# Using Selenium?

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.

  1. 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.

  2. 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

Answers (1)

Norayr Sargsyan
Norayr Sargsyan

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

Related Questions