3

I am trying to use sendKeys() on a modal-dialog box on this website. This dialog box appears after clicking Sign In button. I cannot seem to find any way to switch focus on the box. See the gist

I tried using browser.driver.switchTo().activeElement(); in

InvalidLogInUnSuccess: {
        get: function () {
            this.loginButton.click();
            browser.driver.switchTo().activeElement();
            this.email.sendKeys("Test");
        }
    }

with no luck and throws ElementNotVisibleError

Message: ElementNotVisibleError: element not visible (Session info: chrome=41.0.2272.101) (Driver info: chromedriver=2.14.313457 (3d645c400edf2e2c500566c9aa096063e707c9cf),platform=Windows NT 6.3 x86_64) Stacktrace: ElementNotVisibleError: element not visible

Saifur
  • 16,081
  • 6
  • 49
  • 73
  • Does `browser.switchTo().alert()` help? ([reference](http://stackoverflow.com/a/19884387/771848)) – alecxe Mar 28 '15 at 23:18
  • @alecxe thanks for the quick answer. It did not help just tried. Getting ` NoSuchAlertError: no alert open` and I, also added a 2s hardcoded delay after the click to make sure it's the loading issue. But no luck – Saifur Mar 28 '15 at 23:21
  • 1
    Yeah, sorry, just checked it out, let me debug a bit. Thanks. – alecxe Mar 28 '15 at 23:22

2 Answers2

5

I've experienced a similar issue while testing an internal application when a popup was being opened with an animation effect (I think it is a culprit here) which had me think about waiting for an element inside the popup to become visible.

visibilityOf expected condition works for me in this case:

var email = element(by.css('.container.login.ng-scope #email'));
browser.wait(EC.visibilityOf(email), 5000);

email.sendKeys('test');

where EC is something I usually define globally in the onPrepare():

onPrepare: function () {
    ...

    global.EC = protractor.ExpectedConditions;
},

Just a side note, I think the locator could be improved here:

  • ng-scope is not something I would rely on
  • there is a model defined on the email field, how about:

    element(by.model('email'));
    

FYI, the complete spec I've executed:

"use strict";

describe("gifteng test", function () {
    var scope = {};

    beforeEach(function () {
        browser.get("http://www.gifteng.com/?login");
        browser.waitForAngular();
    });

    describe("Logging in", function () {
        it("should send keys to email", function () {
            var email = element(by.css('.container.login.ng-scope #email'));
            browser.wait(EC.visibilityOf(email), 5000);

            email.sendKeys('test');
        });

    });
});
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • Why does webstorm complaining about [ExpectedConditions](http://prntscr.com/6mmhiu) – Saifur Mar 28 '15 at 23:30
  • @Saifur expected conditions were introduced in protractor `1.7.0`. Are you using `1.7.0` or above? – alecxe Mar 28 '15 at 23:31
  • @Saifur also, do you have `angular-protractor-DefinitelyTyped` and `selenium-webdriver-DefinitelyTyped` libraries enabled in settings? – alecxe Mar 28 '15 at 23:33
  • No sure I am going to check the version. I pulled it though webstorm [libraries](http://prntscr.com/6mmj6b) – Saifur Mar 28 '15 at 23:34
  • @Saifur you can also run `npm list protractor` to check what version you have currently installed. – alecxe Mar 28 '15 at 23:38
  • Huh! I did not have `Protractor` installed. Just installed and going to try the your solution – Saifur Mar 28 '15 at 23:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/74018/discussion-between-saifur-and-alecxe). – Saifur Mar 28 '15 at 23:43
0

Protractor works with promises you should write :

  InvalidLogInUnSuccess: {
            get:  async() => {
                await this.loginButton.click();
                await browser.driver.switchTo().activeElement();
                await this.email.sendKeys("Test");

just apply Promises before protractor code. I removed function and write async. so i applied async/await.

reference: Link

Neh18
  • 152
  • 1
  • 12