We have similar requirement, working on chrome add-on with Selenium WebDriver. As '@Aleksandar Popovic' said, we can't click chrome extension icon with WebDriver, as icon is out of the Webpage.
We make use of sikuli (Automation tool that make use of image recognition), to click the chrome add-on. After that add-on popup will be another browser window, so use switch window to perform actions on add-on popup.
Here is the sample code in Java using both Selenium Webdriver and Sikuli.
Sikuli will run based on image recognition. Before running the code, the screen shot of the chrome browser and crop it so that only Addon is available in the image. Save that image as "AddonIcon.png".
Sikuli will match that image (In our case AddonIcon.png ) on screen and simulate the click action on it.
import java.io.File;
import java.util.List;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.sikuli.script.App;
import org.sikuli.script.FindFailed;
import org.sikuli.script.Pattern;
import org.sikuli.script.Screen;
public class PageTest {
public static void main(String[] args) {
// Opening chrome with that addon
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("Path to ur chrome addon (.cxt file)"));
System.setProperty("webdriver.chrome.driver", "path to chromedriver.exe");
WebDriver driver = new ChromeDriver(options);
driver.manage().window().maximize();
// Creating object to the Sukali screen class
Screen s=new Screen();
//Finding and clicking on the Addon image
try {
s.find("Path to the 'AddonIcon.png'");
s.click("Path to the 'AddonIcon.png'");
} catch (FindFailed e) {
e.printStackTrace();
}
//Wait until new Addon popup is opened.
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.numberOfWindowsToBe(2));
// Switch to the Addon Pop up
String parentWindow= driver.getWindowHandle();
Set<String> allWindows = driver.getWindowHandles();
for(String curWindow : allWindows){
if(!parentWindow.equals(curWindow)){
driver.switchTo().window(curWindow);
}
}
/***********Ur code to work on Add-on popup************************/
}
}
I hope this will help you.