Giter Site home page Giter Site logo

Comments (17)

juliemr avatar juliemr commented on May 5, 2024

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.

rlrhett avatar rlrhett commented on May 5, 2024

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.

rlrhett avatar rlrhett commented on May 5, 2024

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.

juliemr avatar juliemr commented on May 5, 2024

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.

rlrhett avatar rlrhett commented on May 5, 2024

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.

DanielaValero avatar DanielaValero commented on May 5, 2024

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.

jasonnjit avatar jasonnjit commented on May 5, 2024

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.

jasonnjit avatar jasonnjit commented on May 5, 2024

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.

balakmr08 avatar balakmr08 commented on May 5, 2024

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.

DanielaValero avatar DanielaValero commented on May 5, 2024

Hello,

I am not currently active with this issue. Can't help right now. Sorry

from protractor.

prakashomp avatar prakashomp commented on May 5, 2024

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.

balakmr08 avatar balakmr08 commented on May 5, 2024

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.

jasonnjit avatar jasonnjit commented on May 5, 2024

@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.

balakmr08 avatar balakmr08 commented on May 5, 2024

@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.

latobibor avatar latobibor commented on May 5, 2024

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.

sophiaatif avatar sophiaatif commented on May 5, 2024

Hello, I have the same issue. I am using :

  1. Selenium WebDriver dll. Version 2.53.0 Installed by Nuget
  2. 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.

shane-reaume avatar shane-reaume commented on May 5, 2024

For a single pop-up I just do browser.switchTo().frame(1); and works like a champ.

from protractor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.