How to click on chrome extensions using selenium? - selenium-webdriver

I have to click on chrome Extensions button present in address bar in web automation project.
I have no clue how I can click on it using Selenium Webdriver.
Please check attached screen shot for your reference.
Below code snippet which I am using, but not sure click I can click on Extensions button?
System.setProperty(
"webdriver.chrome.driver",
"D:\\drivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions ();
options.addExtensions (new File("D:\\CRX-Extractor-Downloader.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities ();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new ChromeDriver(capabilities);
driver.manage().window().maximize();
driver.get("https://www.google.com");
Thread.sleep(5000);

You can assign a shortcut to the extension you want to click. For example, after = 'CTRL + U' you can send it with sendkeys while the test automation is running on the page.
How to Open Extensions With a Keyboard Shortcut in Any Browser
= https://www.makeuseof.com/open-browser-extensions-keyboard-shortcut/

Related

How to open a new tab using selenium webdriver using Java?

I am trying to open a new tab using Selenium Webdriver and Java, and have used the below code, but it is not opening any new tab and no error message is displayed during the run.
Actions act = new Actions(driver);
act.keyDown(Keys.CONTROL).sendKeys("t").keyUp(Keys.CONTROL).build().perform();
Using the above code I am trying to open a new tab by pressing CTRL+T from keyboard. Please help me.
try this
String selectLinkOpeninNewTab = Keys.chord(Keys.CONTROL,Keys.RETURN);
driver.findElement(By.linkText("urlLink")).sendKeys(selectLinkOpeninNewTab);
or use
((JavascriptExecutor)driver).executeScript("window.open();");

Not able to save firefox profile plugin activation changes using selenium webdriver

When i am opening my same firefox profile through selenium webdriver, each time I have to activate shockwave player manually and changes are not getting saved in firefox profile.
Is there any way to activate plugins through script automatically or save changes in firefox profile for later use.
ProfilesIni profile = new ProfilesIni();
System.setProperty("webdriver.gecko.driver","C:\\Users\\Test-pc1\\geckodriver-v0.16.1-win64\\geckodriver.exe");
FirefoxProfile myprofile = profile.getProfile("SeleniumTest");
WebDriver driver = new FirefoxDriver(myprofile);
myprofile.setPreference("dom.ipc.plugins.enabled.Shockwaveflash.exe", "true");
I hope it will help you to achieve, what you want.
http://toolsqa.com/selenium-webdriver/custom-firefox-profile/ You can refer this.
Once you created your FF profile then, launch it and click on Option menu in right top corner,Select Options.
Select Application, And select the application and say savefile
Once you done, it then run you test with this profile.As mention in the link above.

Windows Popup appears while saving data in Chrome

I am creating some data and click on Save button. Manually when i do it there is no popup at all. But in automation browser of chrome i could see a popup appears asking to stay in page or leave page. How can i avoid the popup in automation script?
As per my knowledge, we have to create profile for chrome driver. I used the below whicc is not working for me. Can someone plssss plssss help me out on this
String userProfile= "C:\\Users\\user_name\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\";
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir="+userProfile);
options.addArguments("--start-maximized");
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.google.com");
is there any specific reason that you are using ChormeOptions?
You can simply use the below code, and it'll work fine and no popups.
System.setProperty("webdriver.chrome.driver","pathToChromeDriver");
WebDriver driver = new ChromeDriver();
driver.get("http://www.google.com");

Profile setting of browser to be used with selenium webdriver

for mozila we use firefoxprofile class to deal with profile setting. I want to know ho do we deal with chrome and IE to set profile i.e. which do we use to deal with profile setting for IE or CHROME.
Anyone can help me out?
thank you..!!
With Firefox, we use Profiles.
With Chrome, we use Options.
eg:
ChromeOptions options = new ChromeOptions();
options.addArguments("--ignore-certificate-errors");
options.addArguments("--disable-popup-blocking");
options.addArguments("--disable-translate");
options.addArguments("--start-maximized");
With IE, we use Derired Capabilities.
eg:
DesiredCapabilities ieCapabilities = DesiredCapabilities.internetExplorer();
ieCapabilities.setCapability("unexpectedAlertBehaviour" , "ignore");

How to create a new tab or window using Selenium Webdriver in Chrome browser

I am trying to add a new tab using Webdriver 2.0 in Chrome but couldn't get the result.I have followed few answers provided in different forums.As I am very new to java and the answers available are more specific to Java scripting,I have posted this query to get a simple solution if possible.
E.g : The following statement is not triggering any action but the result in Selenium shows pass. Please advise.
driver.findElement(By.tagName("body")).sendKeys(Keys.CONTROL +"t");
When you can open a chrome window using
WebDriver driver = new ChromeDriver();
You can simply open a new window using
WebDriver driver2=new ChromeDriver();
You can access driver and driver2 in parallel or sequential.
To close a window do driver.close();
With the latest versions of selenium you can create a new tab, the line in the official github repo.
In C# is something like this:
ChromeDriver driver = new ChromeDriver();
driver.SwitchTo().NewWindow(WindowHint.Tab);
here is the junit test of java for creating a new tab

Resources