I am using Selenium 2.40.0 jar and Firefox 27.0 to test my web application.
I am facing the issue while focusing on specific element since onstart the focus is not on Firefox window. how do I get the focus on Firefox window for focus element to work?
Thanks for the help!
I hope using
driver.manage().window.maximize();
will set the focus on window by default.
Edit :
With Selenium RC you can try these two more functions (Any of these should work)
selenium.windowFocus();
selenium.selectWindow(windowID or windowName);
To get the window ID and names at run time you can use these functions :
selenium.getAllWindowIds();
selenium.getAllWindowNames();
These will return an array of IDs and Names of all opened broswer windows via selenium.You have to select as per your need.
On top of all this I would recommend you to use Selenium Webdriver in place of Selenium RC if possible as selenium RC is now depricated. The above given function driver.manage().window.maximize(); is for Webdriver only. Using webdriver you can avoid these small issues easily.
Migrating from Selenium RC to Selenium Webdriver
Related
I have used '--auto-open-devtools-for-tabs' to open developers console while running selenium automation. By default its opening in Elements tab.I want to switch to Network tab or console tab. Is there any way to do it ?
devtools:
preferences:
panel-selectedTab: '"network"'
This worked Thanks to #wOxxOm
I am trying to select the first device from popup to cast using selenium, capybara but I am not able to do it. Please find the popup below
I have tried following and it does not seem to be working
popup = page.driver.browser.window_handles.last
page.driver.browser.switch_to.window(popup)
page.driver.browser.switch_to.alert.accept
page.driver.browser.switch_to.alert.dismiss
page.driver.browser.switch_to.alert.text
Please provide sugggestions!
You can't - that's a system dialog and selenium can't interact with it once opened. It MAY be possible to set a default to launch and prevent the dialog from opening via chrome command line switches but I'm afraid I don't know what that would be.
I have a ruby script to test a web page in Firefox. it sends mouse or keyboard events pragmatically to Browser but when hardware mouse is moved, it affects my test.
How can i configure Firefox to forget hardware mouse and keyboard events?
You could use Xvfb which will provide a virtual screen for Firefox to open in. Basically you start Xvfb with a screen number in and point Firefox at that screen by running export DISPLAY=:XX. You could use PhantomJS but I wouldn't recommend it because it's doubtful that any users will ever use it; better to test with a browser that people use.
Info on setting up Xvfb
http://www.installationpage.com/selenium/how-to-run-selenium-headless-firefox-in-ubuntu/
How do I run Selenium in Xvfb?
I recommend the headless browser PhantomJS. It works with webdriver and pretty much all Ruby testing tools. Being headless, you must send mouse and keyboard events programmatically. The user's mouse and keyboard will have no effect.
You will also notice that the tests are faster!
I have noticed that while running multiple selenium firefox tests in parallel on a grid that the focus event handling is not working correctly. I have confirmed that when each of my tests is run individually and given focus of the OS the tests pass 100% of the time. I have also run the tests in parallel on the grid with Chrome and not seen the issue present.
I have found the following thread on google groups which suggests launching each browser in a separate instance of xvfb may be a viable solution.
https://groups.google.com/forum/?fromgroups#!topic/selenium-developers/1cAmsYCp2ho%5B1-25%5D
The portion of the test is failing is due to a jquery date picker which is used in the project. The date picker launches on a focus event and since there are multiple selenium tests executing at the same time the webdriver test executes the .click() command but focus does not remain long enough for the date picker widget to appear.
.focus(function(){ $input.trigger("focus"); });
jQuery timepicker addon
By: Trent Richardson [http://trentrichardson.com]
My question is if anyone has seen this before and solved it through some firefox profile settings. I have tried loading the following property which had no affect on the issue.
profile.setAlwaysLoadNoFocusLib(true);
The test fails in the same way as it did before with that property enabled and loaded in the Remote Driver Firefox Profile.
I need a way ensure the focus event is triggered 100% of the time or to solve the issue of multiple firefox browsers competing for focus. Considering Chrome displays none of these issues I wonder if it may also be considered a bug in firefox.
Thanks!
#djangofan: Wrong. You cannot lock the focus. After you requested focus in one window and before you trigger an action, another window requests focus, and your action (like sending keys to input field) just doesn't work. This happened in our tests several times daily. It was hard to reproduce, because with each test run it failed on different places. A solution is to execute each browser in a separate display. E.g. you can use Xvfb:
Xvfb ... -screen 1 1200x800x24 -screen 2 1200x800x24 ...
Then when you start a browser, assign a separate screen to it:
browser.setEnvironmentProperty("DISPLAY", ":N.1");
browser.setEnvironmentProperty("DISPLAY", ":N.2");
...
I've had the same issue in my continuous integration environment with Jenkins.
After a long research i found an old bug in firefox that led to a new config flag to avoid those problems.
The solution is to enable this flag on the firefox profile that the tests use. The flag is focusmanager.testmode, set it to true.
The explanation is that the focus events are triggered only when firefox window is active. If you run multiple test you have multiple windows so only the active one triggers the focus events. With this param the events are trigered even for non active windows.
You can wrangle this and get it under your control with no problem. First write a method to identify the popup window by its window handle id. Then, use a JavaScriptExecutor to execute "window.focus()" in javascript to force the window to be focused just before you perform another action. Then, you can close the popup by its window handle name if necessary.
Every time I launch a Firefox instance via Selenium RC I get 3 windows that I don't need appearing:
the add-ons windows notifying me that
"3 new add-ons have been installed"
(since I'm using a custom profile for
Selenium to which it evidently adds
the DocumentReadyState, KillFF, and
Selenium RC Runner add-ons)
the http://localhost:4444/selenium-server/core/Blank.html?start=true window
the dual window with two tabs starting with chrome://src/content/RemoteRunner.html?sessionId=... each
I don't need any of these to be visible, and each time I have to manually close the add-ons window, to minimize the two other windows, and to maximize the main browser windows which Selenium controls. After going through this too many times, I got annoyed enough to seek a solution:
Is there any way to automate closing the add-ons window and minimizing the two other windows?
By the way, I'm on OS X so I'd also appreciate some alternative solution which automates this via the OS instead of directly using Selenium.
There's a few preferences you can change in your custom profile to prevent the addons window and the additional tab on startup:
Set the extensions.lastAppVersion preference to the version of Firefox that you have installed.
Set the extensions.newAddons preference to false.
Set the extensions.update.notifyUser preference to false.
There might be some more, perhaps others can provide their suggestions in comments or their own answers.
As long as Selenium is running in multi window mode (the default mode) you'll get two browser windows. You could either maximize the main window using the following command:
selenium.windowMaximize();
Or use the multiWindow command line parameter to disable the use of multuple windows and just use a single window - note that this causes issues on some websites, especially if they attempt to break out of frames.