Comments (17)
I usually just look through the webdriver code when trying to find documentation. Check out https://code.google.com/p/selenium/source/browse/javascript/webdriver/webdriver.js and search for 'switchTo'.
I think your problem is that popUpHandle is not defined until after ptor.getAllWindowHandlers(), so when you run ptor.switchTo().window(popUpHandle)
it's not yet defined. I can't quite tell though - could you post the entire test?
from protractor.
I am not sure I understand what you are saying. ptor.getAllWindowHandlers()
is run in the BeforeEach setup. In fact, I have it in a runs/waitFor block to make sure that it has finished and the promise has been fulfilled before running the test. As far as I can tell ptor.switchTo().window(popUpHandle)
is being run after ptor.getAllWindowsHandlers()
has returned. Every test I run before the switchTo()
including expect(popUpHandle).toBeDefined()
passes.
Regardless, that is the entire test. Here it is as one block of text if that helps:
var Pby, parentHandle, popUpHandle, ptor, util;
util = require('util');
Pby = protractor.By;
parentHandle = {};
popUpHandle = {};
beforeEach(function() {
var handlesDone;
ptor = protractor.getInstance();
handlesDone = false;
ptor.get('#/');
runs(function() {
return ptor.findElement(Pby.className('btn')).click();
});
waits(3000);
runs(function() {
return ptor.getAllWindowHandles().then(function(handles) {
popUpHandle = handles[1];
parentHandle = handles[0];
handlesDone = true;
});
});
waitsFor(function() {
return handlesDone;
});
});
describe('login', function() {
return it('should switch to popUp\'s handle', function() {
var handle;
expect(popUpHandle).toBeDefined();
handle = driver.switchTo().window(popUpHandle).getWindowHandle();
expect(handle).toEqual(popUpHandle);
});
});
from protractor.
Any further thoughts? Is this a bug? Is anyone else having this issue? Does this problem occur with straight webDriverJS? Is there more I can add to shed light on this problem? I am completely stalled on e2e testing unless I can figure out how to log into the app, so I am open to any suggestions.
Thanks.
from protractor.
This is indeed an issue with the control flow. In protractor, expect
is patched so that it understands webdriver promises, and waits for them to resolve before executing. That's why your expect(popUpHandle).toBeDefined();
is passing, but popUpHandle
is still empty later.
You should be able to fix by rearranging your test like this:
var Pby ptor, util;
util = require('util');
Pby = protractor.By;
var handlePromise;
beforeEach(function() {
ptor = protractor.getInstance();
ptor.get('#/');
ptor.findElement(Pby.className('btn')).click();
handlePromise = ptor.getAllWindowHandles();
});
describe('login', function() {
return it('should switch to popUp\'s handle', function() {
handlePromise.then(function(handles) {
var popUpHandle = handles[1];
var handle = driver.switchTo().window(popUpHandle).getWindowHandle();
expect(handle).toEqual(popUpHandle);
});
});
from protractor.
That solved the undefined error. I still don't understand why the waitsFor didn't do the job, but at least I can move on with setting up tests. Thanks!
from protractor.
Just as information for other possible users, I modified a bit the promise handle:
var handles = handlePromise.then(function (handles) {
popUpHandle = handles[1];
var handle = browser.switchTo().window(popUpHandle);
handle = browser.getWindowHandle();
expect(handle).toEqual(popUpHandle);
browser.driver.executeScript('window.focus();');
});
And it worked beautifully. After this point I could send the data to the inputs in the window and do whatever I wanted with it. Pretty.
from protractor.
Hi @DanielaValero , I tried the way you provided here, I got an error. Could you please check it? I posted it here: http://stackoverflow.com/questions/25873294/how-to-switch-to-a-new-pop-up-windowa-non-angular-app-to-run-protractor
Thank you.
from protractor.
Hi @juliemr, could you please check this issue? http://stackoverflow.com/questions/25873294/how-to-switch-to-a-new-pop-up-windowa-non-angular-app-to-run-protractor. Thank you.
from protractor.
Hi @juliemr and @DanielaValero , me also facing the same issue reported by @jasonnjit . can u please provide me the solution
Thanks in ADVANCE!!!!
from protractor.
Hello,
I am not currently active with this issue. Can't help right now. Sorry
from protractor.
HI,
Iam also having same problem with angularJS page .
The size of handles are showing only.
how to enter text in popup text field.
from protractor.
HI guys ,
My pop up is also angular based , so my friends asked me to use some what like this:
element(by.id("").element(by.model("<model_name>")).sendKeys("value");
and its working for me.
from protractor.
@balakmr08 Is that working for a pop-up? Cause I found switchTo() only works for a new window or a new tab, but not a new pop-up.
from protractor.
@jasonnjit : yes , its working for popup . U need to use any specific attribute to get into the popup (like id , name or css of the popup) and using this we can access inner elements
from protractor.
Hi everyone,
I can still reproduce this with 3.0.0 and webdriver 2.53.0. Code:
it('checks tabs', () => {
const url1 = 'http://stackoverflow.com/';
const url2 = 'http://programmers.stackexchange.com/';
let windowHandles = {
oldTab: '',
newTab: ''
};
await browser.get(url1);
await browser.getWindowHandle().then(handle => {
windowHandles.oldTab = handle;
});
await browser.executeScript('window.open("' + url2 + '", "whatever")');
await browser.getAllWindowHandles()
.then(handles => {
expect(handles[0]).toEqual(windowHandles.oldTab);
windowHandles.newTab = handles[1];
return browser.driver.switchTo().window(windowHandles.oldTab);
})
.then(() => {
let handle = browser.driver.getWindowHandle();
expect(handle).toEqual(windowHandles.oldTab);
})
.then(() => browser.sleep(6000));
});
If you are using stackoverflow, here's the link for the same question there: http://stackoverflow.com/questions/36578927/protractor-3-0-0-webdriver-2-53-0-switching-tabs-error
from protractor.
Hello, I have the same issue. I am using :
- Selenium WebDriver dll. Version 2.53.0 Installed by Nuget
- IEDriverServer.exe Version 2.53.0 64 bit version downloaded from Selenium Website
My code is same as @latobibor 's code, and it gets stuck on line
browser.driver.switchTo().window(windowHandles.oldTab);
Is it a Selenium Bug, or is this the wrong syntax to Switch Window Handle?
when i debug the issue, i get the following exception after waiting a long time :
An exception of type 'OpenQA.Selenium.WebDriverException' occurred in WebDriver.dll but was not handled in user code
Additional information: The HTTP request to the remote WebDriver server for URL http://127.0.0.1:4444/wd/hub/session/36fa4074-3b34-4dea-9da8-c8278b135c4f/window timed out after 240 seconds.
from protractor.
For a single pop-up I just do browser.switchTo().frame(1);
and works like a champ.
from protractor.
Related Issues (20)
- Twistlock security scan shows that private keys are stored in the container
- Support on Protractor after 2022 and any plans for licensed version HOT 7
- Error: Timeout - Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL. HOT 4
- Callback function is taking long after completing the run in the protractor testcase
- [BUG] Upgrade transitive dependency "[email protected]" to fix CVE-2021-3918 HOT 1
- [BUG] input with dropdown use clear the selected tag won't remove, and click will click on the text not the element.
- Is protractor no longer working when using Angular 13? HOT 8
- protractor.Key.chord() broken in the latest chromedriver HOT 3
- Prototype Pollution in minimist
- qs version CVE-2021-44907 (High) detected in my repo dependencies
- need support for finding element under shadow root HOT 3
- Feature request - html to pdf
- Git.io deprecation notice
- Getting the ERROR "This driver instance does not have a valid session ID (did you call WebDriver.quit()?) and may no longer be used." When I try to use restart() or close() method HOT 2
- Deprecated warning with Protractor HOT 2
- Interview partners for research about communication in GitHub projects wanted
- Can existing Protractor automation scripts developed in year 2020 supported on windows 2019 OS server
- webdriver Manager , chrome version higher then 114 HOT 3
- Migrate Protractor to Playwright
- Meera HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protractor.