Using Selenium IDE with Windows7 and Firefox, an automatic click on a link may produce either a new tab or a new window.
close() closes the original window or tab, not the new one. Maybe if I had the ID of the newly created one I could select it and then close it but I don't know how to do this automatically. I've asked on the Selenium forum and read the questions here, but they focus on WebDriver, not the IDE. Any help would be appreciated!
Stig
I had same problem and found a solution:
click on link that opens the new tab
add command waitForPopUp
set focus to new tab via command selectPopUp
make your verifications or other commands regarding to your content in new tab
use command close to close tab
use command selectWindow to set focus to the old window
Screenshot of my Selenium IDE commands:
That works for me.
Use selectWindow(windowID) command to switch to new window in Se IDE. You can select new window by its windowID/name/title.
Hope this helps...
Agreed with surya use selectWindow(windowID), you can get the window title by right click on the page check the option verifyTitle and in front of that you have your Title. Hope it helps out.
selectWindow(windowID) has option to mention title of the webpage/window as a way to identify the target window.
syntax = selectWindow title=My Special Window
note: title = title of webpage that is visisble in webpage's title bar. Or right click on webpage and select menu "Page source". In source doc, select the text between ....
So if the title of webpage = My Special Window, you will see My Special Window.
Hope this will help.
Swasati Paul
You could use the iterator to iterate amongst the windows, close the new window and come back to the originalWindow. And you can put this under the try block because it will only iterate if a new window opens. Or else, it will continue executing normally in the current window.
try{
Set <Strings> ids = driver.getWindowHandles();
Iterator <String> it = ids.iterator();
String currentPage = it.next();
String newPage = it.next();
driver.switchTo().window(newPage);
driver.close(); //it will close the new window and automatically come back to the currentPage
}
finally
{
//continue with your script here
//this script will run regardless of the execution of the execution of the try block
}
Related
I have written codes to click on hyperlink then check the new window URL.
cy.get('a[href*="newlink"]').eq(0).click()
cy.url().should('equal', 'https://www.google.com')
how do i close this window / or not close AND back to the original main test window?
here's a solution i use for swapping between popup windows: https://github.com/jakedowns/CypressHelpers
it would need some tweaking to work directly with .click
but it does enable cy.openWindow and a new cy.switchWindow / cy.closeWindow
under the hood it uses an undocumented
cy.state('document') and cy.state('window') method for context-switching
cy.go(direction, options)
See the documentation for examples
This works for the history in the same tab. Cypress does not support multiple tabs.
you can use cy.go('back')
see here
I'm working on Calypso windows application where I have to click on a tab within a window. When I was executing the script, I see error message saying that "Cannot find the object's parent window" . I have verified that window properties don't change and no other window is opened with same title.
Please suggest how I can click the tab in the window.
call JavaWindow("Back Office Window for").Activate
JavaWindow("Back Office Window for").JavaTab("Pay Role").Select ("Postings")
THE Window Title is dynamic and keeps changing as shown below
Back Office Window for Trade 4562213 (User: polaris_bouser1)
Try
JavaWindow("title:=Back Office Window for Trade.*").Activate
If this helps, use the same statement in your object repository, using the button next to the property . check the regular expression checkbox.... use this link to quickly go through how to use regular expression youtube.com/watch?v=IdIBhl0p6Fo –
I'm trying to Update Links of inDesign documents using ExtendScript, but whenever I open the document the dialog appear asking me if I want to update the link.
I want to do it in the background, so is there a way to prevent this or any dialog from showing?
Thanks
I have found a solution for this particular dialog. This prompt can be disabled from the UI, but also, as with other setting of the application, you can also do in the code.
So here is what I implemented.
//Save the current application setting.
var currentAppSettings = {checkLinksAtOpen: app.linkingPreferences.checkLinksAtOpen};
//Set the value to false to prevent the dialog from showing.
app.linkingPreferences.checkLinksAtOpen = false;
//do some stuff ...
//Set the value back to its original value.
app.linkingPreferences.checkLinksAtOpen = currentAppSettings.checkLinksAtOpen;
There is a setting in InDesign for checking links. What if you modified the default settings in InDesign? Perhaps if you uncheck "Check Links Before Opening Document" it will bypass the dialogue.
I want to open all links in the same window instead in new window.
I tried
profile.setPreference("browser.link.open_newwindow", 1)
but the result is:
WARNING: traffic.loop 0 error: Preference browser.link.open_external may not be overridden: frozen value=2, requested value=1
Is there an another way to open the links in the same window ?
You should modify the firefox profile parameters:
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.link.open_newwindow", 3)
profile.set_preference("browser.link.open_newwindow.restriction", 0)
driver = webdriver.Firefox(firefox_profile=profile)
if this methode does not work, you can set perference using firefox Options:
from selenium.webdriver.firefox.options import Options
opts = Options()
opts.set_preference("browser.link.open_newwindow.restriction", 0)
opts.set_preference("browser.link.open_newwindow", 3)
driver = webdriver.Firefox(firefox_options=opts)
(A) browser.link.open_newwindow - for links in Firefox tabs :
3 : divert new window to a new tab (default)
2 : allow link to open a new window
1 : force new window into same tab
(B) browser.link.open_newwindow.restriction - for links in Firefox tabs
0 : apply the setting under (A) to ALL new windows (even script windows)
2 : apply the setting under (A) to normal windows, but NOT to script windows
with features (default)
1 : override the setting under (A) and always use new windows
I've found a workaround!
JavascriptExecutor js = (JavascriptExecutor) driver;
String script = "document.getElementById('yourFormOrAnchorId').target=''";
js.executeScript(script);
After that you can select your anchor or any of the form elements and click or submit it. The target page will open in the same tab.
This basically changes the current HTML page so that anchors and forms don't force the browser to open new tabs or windows. For testing this might be suboptimal, but it simplifies the writing of tests a lot.
Try this out...
Modify FireFox profile parameters "browser.link.open_newwindow.restriction" and "browser.link.open_newwindow".
FirefoxProfile profile = new FirefoxProfile();
profile.setPreference("browser.link.open_newwindow.restriction", 0);
profile.setPreference("browser.link.open_newwindow", 1);
If you are using Google Chrome then simply install this extension and it will take care of the rest of the task. This extension is also handy to open pop-ups in new tabs which usually opens in new windows. (First you need to download the extension .crx file from given location.)
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/path/to/extension.crx"));
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
ChromeDriver driver = new ChromeDriver(capabilities);
In the selenium config file:
C:\Python27\Lib\site-packages\selenium\webdriver\firefox\webdriver_prefs.json
change the following line from:
"browser.link.open_newwindow": 2,
to:
"browser.link.open_newwindow": 3,
I test it and it worked
According to Selium docs (https://code.google.com/p/selenium/wiki/FirefoxDriver) the following property webdriver.firefox.profile controls the firefox profile used.
Which is where firefox gets the browser.link.open_newwindow on start up from. To create a new profile for your tests you can follow the instructions here https://support.mozilla.org/en-US/kb/profile-manager-create-and-remove-firefox-profiles detailed configuration of the profile can be done either by editing the profile's pref.js or firing up the profile and editing it via about:config.
hope this of help!
Actually, Selenium is not responsible of the page opens in a new window or in a same window. It is fully depends upon the Browser settings which you used for execution.
For a sake take Firefox browser
If you want to open all the links in a new window. Do these steps
Open Tools
Click Options
Click Tabs menu
Check the box of Open new windows in a new tab instead.
Now click the link which opens a window. It will opens in a new tab of same window.
I'm new to the testing world, so my question might seem a lil' bit too naive and stupid. At risk of looking/sounding stupid, my question is this:
I've been trying to test the contents in a pop-up window on my company's web app. I've figured out how to detect the pop-up window for now, but i can't get selenium to 'click' on the link inside of that pop-up window. there are multiple pop-ups in this web app so it's really difficult for a newbie like to create a test case.
I tried the click, clickAndWait, mouseDown and mouseKey as an option but it is still not working. can somebody guide me through this?
TIA,
Angela
When the popup appears you will need to move the context of the script over to the window.
You can do this by using the selectWindow | window_ID_from_the_link and then do the clicking.
If that doesn't work you may need to use the openWindow command to create the popup and then start testing against that.
Use getConfirmation/getassert/getprompt according to the type of the pop up you use .....By default they will be clicked with ok option by the server and you have to consume the message from the pop up for the other selenium commands to work correctly.............
The above suggestion is given from my experience in working with selenium RC used with perl..........
Perhaps you can try the FireFox Plugin. You can click through your application and record your steps. After recording the steps you can easily save it as some sort of file or unittest.
I'm not sure about the command you should use for the popups, maybe the firefox plugin will help in this manner (it will create your commands).
If you created the popup with a div tag, U can use following code to stop the selenium server until the popup opens.
int second = 0;
while(!selenium.IsElementPresent(mylink))
{
if(second >= 5)
break;
Thread.Sleep(1000);
second++;
}
After a popup opens, Now you can click on any link inside the popup.You have to use the below code.
selenium.click("id=popup_link"); (popup_link is the id of the link present on the popup)
Good Luck.
Not sure if this is what you are looking for, but if you want to click on something specific that Selenium is not able to handle - like browser pop-ups or other pop-ups, you can use Sikuli Script. Sikuli does an image comparison and clicks on the same - this is very powerful.
Here is the link: http://www.sikuli.org/