Give focus to an externally launched browser in Selenium - java

I am opening a window based application in my desktop using Sikuli. After clicking on a button in that application, a browser is opened.
Can I get focus on that browser in Selenium? Can Webdriver detect an already opened browser?

The answer to that is no. In order for Selenium Webdriver to control a browser it must be instantiated as WebDriver object creating a session ID, etc..
One possible solution might be to somehow intercept the URL that is generated by the desktop application and use it to launch a Webdriver instance.

Related

How to switch my IE browser session to chrome browser session?

My 'sign in' is in IE browser and after sign in if i click on the links they get opened in chrome browser. How to switch my current browser from IE to chrome during the same Test case. If i create a instance of chrome driver, it opens a new browser altogether and if i use getWindowHandles to get chrome browser count, it gives one. It didn't recognize the chrome browser opened by the IE browser. Please guide me.
I thought opening a new instance of chrome driver would solve my problem but it doesn't let me go to the session created through IE browser chrome browser.
As far as I know, you cannot do it with Selenium as the driver instance, once created, remains with the same browser until quit.
Firstly, have you set you default browser on PC as IE browser? In that case, the new links may also get opened with IE browser so handling windows/tabs would work.

Selenium Using current session to re-open the browser

I am trying to open chrome, close it and then open it again using the same session.
Is a thing like this even possible? I've looked through the internet/stackoverflow and tried using driver.Close(); but with no luck.
Anybody has some experience with this and mind helping me?
thanks
In Selenium Webdriver, a browser session can be closed using two webdriver commands: close() and quit(). The situations in which they are used are briefly explained below:
close() is a webdriver command which closes the browser window which is currently in focus.
During the automation process, if there are more than one browser window opened, then the close() command will close only the current browser window which is having focus at that time. The remaining browser windows will not be closed. The following code can be used to close the current browser window:
driver.close() //where, ‘driver’ is the Webdriver object.
quit() is a webdriver command which calls the driver.dispose method, which in turn closes all the browser windows and terminates the WebDriver session.
If we do not use quit() at the end of program, the WebDriver session will not be closed properly and the files will not be cleared off memory. This may result in memory leak errors.
The following code can be used to close all the browser windows:
driver.quit() //where, ‘driver’ is the Webdriver object.
If the Automation process opens only a single browser window, the close() and quit() commands work in the same way. Both will differ in their functionality when there are more than one browser window opened during Automation.
Source: Reference link

WebPage works if opened manualy. Returns "Window language could not be determined" if opened via Selenium

I am dealing with a small problem. I am working on automating few tasks in a web application,i can open the webpage,enter the login,click login,BUT then it starts to act strange. If i click on the login manualy it logs in without a problem.
But if i try to do it via selenium (JAVA jdk1.7.0_75,selenium-java-2.53.1,running on IEDriverServer_Win32_3.4.0) the page opens with error An error has occured.
java.lang.NullPointerException. and with "Window language could not be determined "
The page is on the intranet. I guess the application has a problem with the Webdriver (everything works if i try to automate the task using the VBS).
Dont you know any "workaround" for that?
(I can use only IE,because chrome no longer supports NPAPI so the application does not work in chrome)
InternetExplorerDriver driver = new InternetExplorerDriver();
driver.get("*the webpage*");
driver.findElementByName("userid").sendKeys("*login*");
driver.findElementByName("password").clear();
driver.findElementByName("password").sendKeys("*password*");
driver.findElementByName("ctr").sendKeys("*number*");
driver.findElementByName("menuType").click();
driver.findElementByLinkText("OK").click();
I think the problem is somewhere in the settings,because as i mentioned,if o open the browser manualy and login,it works,no errors and i get into the app.
But the webdriver "browser" has somehow different settings (i think) so it does not work. Problem is,that we have restricted access to the settings of browser,so i cant do much about that.
Thank you very much for any suggestions/answers/tips!!
Kind Regards,
Jerry Woodburn

What is the mechinism used for commiunication between webdriver and browser

Anyone can explain how communication happen between browser and web-driver?. How does webdriver object read and identify html elements in browser ?. For that what is the relationship between webdriver object and browser and how to build the relationship browser and webdriver object?
driver = new FirefoxDriver();
driver.findElements(By.id("element"));
The communication between webdriver and browser happens through a json-wire protocol which is specified in the W3C documentation. All browsers that webdriver supports, uses this same protocol.
How does webdriver read and identify elements in a page? This varies from browser to browser.
Firefox - webdriver gets installed as a plugin in your browser while running the test. The webdriver server will send the json-commands to this plugin and those commands will get executed in the browser. The plugin is built within the webdriver jar file. It will get installed while running the test.
Chrome - For testing chrome, you would also need a chromedriver.exe file. This chromedriver.exe acts similar to the firefox plugin. It can receive the commands from webdriver server and execute it on the browser
IE - Similar to Chrome, IE executes with the help of InternetExplorerDriver.exe.
You can understand more about the functioning by looking at the different DriverFile source code in github.
You can also get an understanding about the working from here - http://www.aosabook.org/en/selenium.html.
I am not sure how updated this page is, but should help to understand the concept.

Page Not Loading in Firefox after Authentication

I have written Java code using Selenium Webdriver and AutoIt that opens a Firefox driver, navigates to a page that requires authentication via selection of a soft certificate, selects the appropriate certificate when the Certificate Selection window pops up, and clicks OK, at which point the page I'm accessing should load but instead it just loads a blank "New Tab"; a new tab isn't opened per se, just the current tab remains blank with the title of "New Tab".
If I perform this process manually (without having Selenium Webdriver open a Firefox driver and I just launch it myself) using the same exact Firefox profile, the page loads after authentication just fine. I should also note that the page loads successfully using driver instances of Internet Explorer and Chrome.
I am using Firefox v33.1, IE 10, and Chrome v38. Finally, I should note that this has nothing to do with my automated certificate selection process because even if I only have Selenium Webdriver open a Firefox driver and stop there and then I take the wheel and select the certificate myself and click OK, it still does the same thing.
I think Selenium Webdriver might have some annoying guard built into the Firefox drivers it instantiates that prevents it from loading pages requiring authentication. If this is the case, does anyone know how to possibly disable that?
Java needed to be set to "Always Activate" under the Firefox Add-ons -> Plugins. Before it was set to "Ask to Activate" but it never explicitly asked to activate after I selected the certificate, thus the page wouldn't load.

Categories