How to bring browser to front using Selenium WebDriver? - selenium

I've a test where it handles login system popup using Robot of Java. But because of some issues, other applications or browser instance come to front and Robot could not perform actions on system popup of Windows.
Hence before interacting with system popup using Robot, I want to bring that browser to front on machine. I tried following but it did not help -
((JavascriptExecutor)driver).executeScript("window.focus();");
Could you please suggest how I can bring it to the front?

Related

How can I access browser extension's popup using selenium?

I want to write an acceptance test for my browser extension. I've tried to initiate an extension via selenium but I can't seem to access a content of popup. Can someone suggest how can I do it with selenium or any other way to write UI/acceptance tests for browser extensions? Thanks.
How can I access browser extension's popup using selenium?
It's not possible. Selenium supports interaction with web view only.
What you can do with Selenium and extension for sure is automatic installation: https://stackoverflow.com/a/16512012/2517622
You may try to use desktop automation tools (e.g. White on Windows platform) for clicking on extension popup but it's not that easy and it's not platform independent as Selenium.
Here is the workaround we came up. Unless someone posts here the "right" solution I will consider this as the best approach.
So eventually, our extension is an iframe which just loads a page content from our website + does some other neat stuff. We simply open that url in a new tab and do regular selenium tests.
Side not: we have considered to write a little javascript wrapper to be able to access ext via main window through javascript. E.g. there is some js in ext that listens to main window's events and perform certain actions. Tho, it is too much efforts and doesn't really sound like a proper acceptance test so we discarded this approach.

Selenium Golang binding without server

There are many selenium webdriver binding package of Golang.
However, I don't want to control browser throught server.
How can I control browser with Golang and selenium without selenium server?
You can try github.com/fedesog/webdriver which says in its documentation:
This is a pure go library and doesn't require a running Selenium driver.
I would characterize the Selenium webdriver as a client rather than a server. Caveat: I have used the Selenium webdriver (Chrome version) from .Net and I am assuming it is similar for Go.
The way Selenium works is that you will launch an instance of it from within code, and it creates a live version of the selected browser (i.e. Chrome) and your program retains control over it. Then you write code to tell the browser to navigate to a page, inspect the response, and interact with the browser by filling out form data, clicking on buttons, etc. You can see what is happening on the browser as the code runs, so it is easy to troubleshoot when the interaction doesn't go as planned.
I have used Selenium to upload tens of thousands of records to a website that has no API and only a graphical user interface. Give it a chance.

How to disable developer tools in webpage opened by selenium driver?

I have created an application in selenium wherein it opens IE browser and enters user id and password by usind selenium's IE driver. However I want to prevent user from inspecting the auto data filled by selenium in the form. User can easily inspect the data using developer tools. So I want to know the way to disable developer tools options in selenium opened webpages.
Your help is highly appreciable.
Thanks.
Instantiate an instance of OpenQA.Selenium.Interactions.Actions then perform keystrokes for the F12 control. This should toggle on/off the developer tools in Chrome, IE, and Firefox.
I would also include a check to see if one of the controls from the devtools is there before toggling this, just to be sure that you don't turn them on instead of off.
c#:
OpenQA.Selenium.Interactions.Actions actions = new OpenQA.Selenium.Interactions.Actions([Instance of IWebDriver goes here]);
actions.SendKeys(OpenQA.Selenium.Keys.F12).Perform();

Run Selenium tests in one browser while using a second browser window

I am running Selenium automation test in one browser, but at the same time, I want to open the browser in another window and do something like checking mail, googling email then active mode or focus is coming to the current working window, not the automation test run browser.
Is it possible to work on the browser while automation test is run?
In general, when doing UI automation, you cannot use the test machine to do any other tasks that involve using the keyboard or mouse.
Since WebDriver automation performs keyboard and mouse input, such as typing text and clicking items, you will be constantly interfering by taking focus away from the WebDriver instance of the browser and doing your own mouse and keyboard interaction in other applications.
This will adversely affect both you and the automation, with neither being able to do what they want to do!
You should either use a separate test machine, or setup a virtual machine using software such as VirtualBox (free).
Did you try doing that?
Selenium uses WebDriver to communicate with a specific instance of a browser, not the currently focused window. So you should be able do continue to use other instances of browser windows. The best thing to do would be try.
If it isn't working, I would recommend getting a VM up and running and using that as your test environment. Generally that is the way I work to keep everything separate.
I ran my tests on Firefox and then used chrome on the side. Otherwise, run your tests on a remote machine.
You can do 2 things
1. Use a third tool to run test cases like Jenkins. so that test will run in memory.
2. If you are using firefox you can create a seperate firefox profile so that if you use firefox at the same time there should be any issue.
To Create new FF profile use below code:
FirefoxProfile profile = new FirefoxProfile();
profile.setAcceptUntrustedCertificates(false);
profile.setAssumeUntrustedCertificateIssuer(true);
DesiredCapabilities dc = DesiredCapabilities.firefox();
dc.setCapability(FirefoxDriver.PROFILE, profile);
WebDriver driver = new FirefoxDriver(dc);

Selenium - dialog box

When the browser launch is initiated by SeleniumRC, a dialog box always comes to ask for username/password to login to our proxy server (however, it is prepopulated with username/password, all has to be done is just press the OK button).
selenium.open("/");
selenium.type("q", "selenium rc");
selenium.click("btnG");
selenium.waitForPageToLoad("10000");
assertTrue(selenium.isTextPresent("Results * for selenium rc"));
// These are the real test steps
//selenium.stop();
After the first command, the dialog box appears and I want to dispose of that dialog box PROGRAMMATICALLY. Any help?
I don't think you'll be able to address this just by using Selenium, that modal dialog is outside the JavaScript boundaries in which selenium works.
The two alternatives I can think of are:
Using WebDriver (soon to be merged into selenium 2.0): has native support over the browser, which allows you to do that kind of stuff.
Using an OS level automation library just for clicking that prompt and you go back to selenium with the rest. The libs available for this things are language dependent, so you will find a lot of different options as Robot for java or pyWinAuto for python.
Update: New alternative:
You can use autoIT as a simple and fast solution under windows.