My problem is when I click on a desktop icon, it opens a link in already opened chrome browser in a new tab. How do I attach with the already opened browser and not a new one?
The below code returns a null because there is no window opened through selenium ofcourse, so yeah.
Set<String> windows = webdriver.getWindowHandles();
System.out.println(windows);
Any suggestions would be of great help. Thanks In advance.
There is no way to attach the chrome window that you've opened from the desktop application to your WebDriver instance.
If you want to be able to control a web page with a Selenium - you must pass your URL to a driver like that:
webdriver.get("https://www.your_link.com");
You might think about the way of getting and storing your URL as a variable and passing it into your code.
That would also be helpful if you add a bit more details about the problem. It's a bit unclear at what stage of the test you open the web page with a desktop application. Selenium can't be used to test desktop applications. Code sample of the test from your project would also help.
Related
We have a terminal application which serves webcontent via iFrames to our clients.
For some reason, it has been decided that we want to automate the test for this server side. I need to visit a page, fill out a form, and submit it - without actually rendering it in a GUI, I believe a headless selenium driver can do this - but I am new to selenium, does anyone have an example of how to do this in java with selenium?
You can use PhantomJS. Here you can find a working example.
I had created a java application for selenium webdriver.
FirefoxDriver driverff= new FirefoxDriver();
used to create a new Firefox instance.
This is working fine.
I want to create a java web application to do the same.
I have embeded the same code in the servlet class in the doget() method and it throws
java.lang.NoClassDefFoundError: org/openqa/selenium/firefox/FirefoxDriver
Can someone tell me how i can fix this?
From an end to end perspective, what oi want to achieve is that a web page (done using servlets) has some buttons which when clicked need to open a selenium web driver and run the selenium scripts. I am assuming the java application for web-driver can be called using servlet.
If there is some other alternative to achieve this, please do suggest.
The error message means that Java can't find the class in question. Make sure it's on the classpath of your web app.
That said, you may run into problems later: Linux web servers often don't have an attached display so no X server is running. That will make it hard to start a browser :-) If that's the case for you, look up Google for "selenium xvnc" or "selenium headless"
I'm currently running my selenium webdriver tests in 2 browsers (studentdriver and tutordriver)
studentdriver = new ChromeDriver();# opening student in chrome browser
tutordriver = new FrefoxDriver();#opening tutor with firefox browser
and I'm student browser first and then tutorbrowser soth that student browser will be behind and tutorbrowser will be on front side. when script running with studentbrowser, it will automatically comes fron and tutorbrowser will be back side but when script start running using tutorbrowser it is not coming front side and it is creating some problem in between.
I need a solution to get tutorbrowser front when script start running on tutorbrowser.
Note: I should not close studentbrowser because I'm closing both the browsers in #After
((JavascriptExecutor) driver).executeScript("window.focus();");
try this with each driver.
Unfortunatly, this is an OS problem. It's up to the window manager to handle the ovelapping, tiling, organisation of the windows, which you can't control directly from your code.
The best bet you'll have is to launch a Sikuli Robot with which you'll be able to bring back the correct window. It's a bit of work, though, to include in your tests, but it can be used from Java with no problem
See the beast at http://www.sikuli.org
I am looking for an example code that will allow me to run Selenium commands against a browser that is already open.
Typically when you start testing with Selenium it opens a new instance of the browser. But I am looking
for a solution where you would run the script and it will just start executing its codes on whatever browser and tab is currently visible.
Is that possible?
As per my knowledge this is not possible with selenium.
You have to open browser during the test script only otherwise it won't be able to identify or capture already opened browser's object.
No its not. There is an old issue still open since 2009.
I've got a need to navigate java-applet programmatically and I am not that keen on Java platform. So lets assume I've got IE process stated with appropriate java applet loaded. Next I need to have some actions taken to this particular applet, like, lets say, sending WM_COMMAND to dialog along with BN_CLICKED code like I do with Windows in C. Assuming it's not a regular window I can refer to using HWND, I would like to ask someone for recommendations on how to do this.
As I understand you want to navigate (sending keystrokes and mouse clicks) a java-applet on the client side. It depends if you own the applet (say: you have the code and can change it) or if the applet is closed source and you just want to remote it.
In the first case use javascript to automate it. Change the containing HTML page to include some Javascript and pass parameters to the applet as described in the Java Tutorials.
If the applet accepts parameters, but you cannot change the HTML page, use a GreaseMonkey alternative for IE.
Your other approach (sending Windows Messages from an extern application to IE) should also work. Start Spy++ (use the 64bit version if you are using a 64bit Windows), choose "Search - Find window..." and drag the "Finder Tool" icon over the applet and release it. You will see then the HWND and if you press search you will see the window inside IE window hierarchy. So, yes you can send keystrokes and mouse clicks to a browser.
If I would automate the browser I would use Geb. You code a "web site test" in Groovy, just look at the Geb index page.
You could try to record a navigation through the applet with FireFox + "Selenium IDE" then export it and try run it in a Java Application with the Selenium IE WebDriver.
Information about Selenium can be found here : http://docs.seleniumhq.org/
Maybe this question will also help you : How to automate Java applet?