1

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);
Norayr Sargsyan
  • 1,737
  • 1
  • 12
  • 26
GRF
  • 171
  • 2
  • 10

1 Answers1

0

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")));
Norayr Sargsyan
  • 1,737
  • 1
  • 12
  • 26
  • Thanks Norayr Sargsyan... I tried that code but title is null and does not click. See this link... https://ibb.co/njxHGhm – GRF Feb 01 '21 at 15:51
  • Thanks @NorayrSargsyan8... I tried that code but title is null and does not click. See this link... https://ibb.co/njxHGhm – GRF Feb 01 '21 at 15:58
  • Try without assigning to a String – Norayr Sargsyan Feb 01 '21 at 16:06
  • Thanks @NorayrSargsyan ... I tried that code but title is null and does not click. See this link... https://ibb.co/njxHGhm – GRF Feb 01 '21 at 16:10
  • Thanks @NorayrSargsyan. I tried this `js.ExecuteScript("window.postMessage('clicked_browser_action', '*')");` and still does not work – GRF Feb 01 '21 at 16:36
  • Hi @NorayrSargsyan,,, Any other ideas for clicking on Extension icon when the driver window opens? – GRF Feb 02 '21 at 01:20