admin管理员组文章数量:1252681
Looking for some help on how I should be getting ahold of a new "pop-up" window that is triggered to display after I click a "login" button.
I am able to get to when the window is displaying but I do not believe that the code I am currently using to grab the window "handle" is working properly. My situation is a bit different in that I am using protractor inside my pages, but the new window comes up is NOT angular based, so I must switch over to using just selenium WebDriver while I am in that window. (Anyone have any idea if there could be issues with this approach?)
Below you can find the code snippet that I am using to create the selenium driver, as well as below that trying to "switch to / grab handle" of the new window that is popping up. I know that it is not working correctly because I keep receiving "No Such Element" errors in the code that follows trying to find a form on the page.
// Create selenium webdriver / driver
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
// Now make sure that the new window is popping up and we are navigating correctly to it
var handlePromise = browser.driver.getAllWindowHandles();
handlePromise.then(function (handles) {
// parentHandle = handles[0];
var popUpHandle = handles[1];
// Change to new handle
browser.driver.switchTo().window(popUpHandle);
var popUpHandleFinal = browser.driver.getWindowHandle();
expect(popUpHandleFinal).toEqual(popUpHandle);
});
Couple things about this:
If I remove the "browser" in the line "browser.driver.switchTo().window(popUpHandle)" so it reads as "driver.switchTo().window(popUpHandle)" I receive back and error that reads as" UnknownError: unknown error: 'name' must be a nonempty string" After doing some searching on this it is because the "switchTo()" method on driver cannot be null. This error is cleared up if I just use the code shown above.
I am not 100% sure if I should be using protractor (global "browser" var) or using the straight "driver" (Selenium) that I set before this as the way to get the windows.
Thank you for your help
Looking for some help on how I should be getting ahold of a new "pop-up" window that is triggered to display after I click a "login" button.
I am able to get to when the window is displaying but I do not believe that the code I am currently using to grab the window "handle" is working properly. My situation is a bit different in that I am using protractor inside my pages, but the new window comes up is NOT angular based, so I must switch over to using just selenium WebDriver while I am in that window. (Anyone have any idea if there could be issues with this approach?)
Below you can find the code snippet that I am using to create the selenium driver, as well as below that trying to "switch to / grab handle" of the new window that is popping up. I know that it is not working correctly because I keep receiving "No Such Element" errors in the code that follows trying to find a form on the page.
// Create selenium webdriver / driver
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().
withCapabilities(webdriver.Capabilities.chrome()).
build();
// Now make sure that the new window is popping up and we are navigating correctly to it
var handlePromise = browser.driver.getAllWindowHandles();
handlePromise.then(function (handles) {
// parentHandle = handles[0];
var popUpHandle = handles[1];
// Change to new handle
browser.driver.switchTo().window(popUpHandle);
var popUpHandleFinal = browser.driver.getWindowHandle();
expect(popUpHandleFinal).toEqual(popUpHandle);
});
Couple things about this:
If I remove the "browser" in the line "browser.driver.switchTo().window(popUpHandle)" so it reads as "driver.switchTo().window(popUpHandle)" I receive back and error that reads as" UnknownError: unknown error: 'name' must be a nonempty string" After doing some searching on this it is because the "switchTo()" method on driver cannot be null. This error is cleared up if I just use the code shown above.
I am not 100% sure if I should be using protractor (global "browser" var) or using the straight "driver" (Selenium) that I set before this as the way to get the windows.
Thank you for your help
Share Improve this question edited Jan 20, 2016 at 17:09 gariepy 3,6746 gold badges23 silver badges34 bronze badges asked Feb 28, 2015 at 23:15 parchambeauparchambeau 1,14111 gold badges35 silver badges57 bronze badges 3 |4 Answers
Reset to default 17As of latest version of Protractor (v2.2) there should not be an issue in using protractor window handles, which returns an array of windows that are currently being displayed. As P.T has pointed out there is no need to invoke a separate driver instance but a browser
global variable will work. The window that invokes popup has array index of 0
and popup window will have an array index of 1
. Below is a sample of switching to the pop up window to work on it.
browser.getAllWindowHandles().then(function(handles){
browser.switchTo().window(handles[1]).then(function(){
//do your stuff on the pop up window
});
});
Hope this helps.
If you are clicking any link or button in order to open a pop up window, add some wait after click using browser.sleep(ms)
.
This worked for me and got rid of an error "missing 'handle' parameter"
element(by.className("name")).click();
browser.sleep(10000); //This line is important
var winHandles=browser.getAllWindowHandles();
winHandles.then(function(handles)
{
var parentWindow=handles[0];
var popUpWindow=handles[1];
browser.switchTo().window(popUpWindow);
browser.switchTo().window(parentWindow);
})
If you are calling https:// url and again redirect to http:// url then this popup is coming because of security issue.
1 - You have to configure both application in https:// or http://
Check if the window is available coz count starts from 0 for window. So, try decrementing the count and use, it might work.. ;) As it worked for me doing that..
本文标签: angularjsSwitching to new window with SeleniumProtractor JavascriptStack Overflow
版权声明:本文标题:angularjs - Switching to new window with SeleniumProtractor Javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738306044a2073835.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
browser.driver
so that should be correct to use. – P.T. Commented Mar 1, 2015 at 17:31