nightwatchjs / nightwatch

Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
https://nightwatchjs.org
MIT License
11.79k stars 1.31k forks source link

browser.keys command does not work in Firefox #2468

Closed kretschmannj closed 2 years ago

kretschmannj commented 4 years ago

This works for Chrome but not on Firefox.

        client
            .keys([client.Keys.COMMAND], () => {
                component.click('.infinite-tree-item:nth-of-type(1)');
                component.click('.infinite-tree-item:nth-of-type(2)');
            });

tried this as well ->

        client
            .sendKeys('#myDiv', [client.Keys.COMMAND], () => {
                component.click('.infinite-tree-item:nth-of-type(1)');
                component.click('.infinite-tree-item:nth-of-type(2)');
            });

Not working.

Originally posted by @chin2km in https://github.com/nightwatchjs/nightwatch/issues/361#issuecomment-342261481

kretschmannj commented 4 years ago

My application has a date field followed by a checkbox. I'm attempting to tab from the date field to the checkbox and then I want to check the box. I have tried three different methods for sending the keys. All three methods work fine in Chrome but fail in Firefox.

method 1:

browser.keys([browser.Keys.TAB, browser.Keys.TAB, browser.Keys.TAB, browser.Keys.TAB, browser.Keys.SPACE])

output in Firefox:

 Error while running .sendKeys() protocol action: An unknown error has occurred.

method 2: browser.sendKeys('#authExpiryDt', [browser.Keys.TAB, browser.Keys.TAB, browser.Keys.TAB, browser.Keys.SPACE])

output in Firefox: Error while running .setElementValue() protocol action: invalid type: sequence, expected a string at line 1 column 8

method 3:

browser.element('css selector', '#authExpiryDt', function (result) {
    // Newer versions of the webdriver like Gecko/IEDriver return the element as "element-6066-11e4-a52e-4f735466cecf" instead of "ELEMENT"
    this.elementIdValue(result.value.ELEMENT || result.value["element-6066-11e4-a52e-4f735466cecf"], [browser.Keys.TAB, browser.Keys.TAB, browser.Keys.TAB, browser.Keys.SPACE])
})

output in Firefox: Error while running .setElementValue() protocol action: invalid type: sequence, expected a string at line 1 column 8

As I am seeing two different errors, there may be multiple issues at play here.

kretschmannj commented 4 years ago

I have some more information ... the .setElementValue error is thrown in Firefox because I'm sending an array of values to sendKeys rather than a string. If I change the value to browser.Keys.TAB+browser.Keys.TAB it will work in Firefox. No such issue in Chrome as it doesn't complain at all and works perfectly fine when I send an array of values.

kretschmannj commented 4 years ago

As for the issue with browser.keys, I ran the test in verbose mode (--verbose) and see this in the output ...

 → Running command: keys ('')
   Request POST  /session/b750e8dd-9ded-408a-b5dd-a79889202186/keys  
   { value: [ '' ] }
   Response 405 POST /session/b750e8dd-9ded-408a-b5dd-a79889202186/keys (1ms)
   { status: -1, value: 'HTTP method not allowed' }
 Error while running .sendKeys() protocol action: An unknown error has occurred.
kretschmannj commented 4 years ago

One more piece of information ... up to now I've been running the test with the webdriver that's built into Nightwatch. For fun, I thought I'd try the selenium server. Still failed but got a different error this time ...

→ Running command: keys ('')
   Request POST  /wd/hub/session/08af23c9-6d89-478f-acec-9ce4d348f0ab/keys  
   { value: [ '' ] }
   Response 500 POST /wd/hub/session/08af23c9-6d89-478f-acec-9ce4d348f0ab/keys (13ms)
   {
     value: {
       error: [
         "Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'",
         "System info: host: 'CA01000JWL2P13L', ip: '10.0.0.40', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_201'",
         'Driver info: driver.version: unknown'
       ],
       message: 'sendKeysToActiveElement'
     },
     status: 9
}
 Error while running .sendKeys() protocol action: sendKeysToActiveElement

  → Completed command: keys ('') (19ms)
stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had any recent activity. If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.

mncrff commented 3 years ago

I am having the same issue with Nightwatch version 1.5.1. Here is my test that is failing:

it('should move focus from the trigger to the first element in the menu', browser => {
    browser.keys(browser.Keys.TAB);
    browser.expect.element('.dropdown-menu li:first-child .dropdown-item').to.be.active;
});

Running just Nightwatch (no selenium); Firefox (82.0) MacOSX 10.15.7:

Error while running .sendKeys() protocol action: An unknown error has occurred.

Error while running .getActiveElement() protocol action: An unknown error has occurred.

Not sure if the activeElement thing is a result of the first step of sendKeys not working, or an additional issue.

Running Nightwatch with Selenium; Firefox (82.0) MacOSX 10.15.7:

   Response 500 POST /wd/hub/session/da603001-3b00-fc42-bf1a-1a6d52273071/keys (21ms)
   {
     value: {
       stacktrace: '',
       message: 'sendKeysToActiveElement\n' +
         "Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'\n" +
         "System info: host: 'REDACTED', ip: 'REDACTED', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.15.7', java.version: '1.8.0_211'\n" +
         'Driver info: driver.version: unknown',
       error: 'unknown command'
     },
     status: 9
}
 Error while running .sendKeys() protocol action: unknown command – sendKeysToActiveElement

Running Nightwatch on Browserstack (assumed using Selenium - please correct me if I'm wrong); Firefox (82.0) on Windows 6.3:

Response 500 POST https://hub-cloud.browserstack.com/wd/hub/session/24f81f432ce9799f227a2853edcd455b65ce1a63/keys (182ms)
   {
     value: {
       stacktrace: '',
       message: 'java.net.SocketException: Software caused connection abort: recv failed',
       error: 'unknown error'
     },
     status: 13,
     sessionId: 'da82323f-2f56-42fb-8469-669bc26d9d6b'
}
 Error while running .sendKeys() protocol action: unknown error – java.net.SocketException: Software caused connection abort: recv failed
Pieras2 commented 3 years ago

Anyone has any workaround? I need it to and in general I guess that ff suxx :/

kretschmannj commented 3 years ago

It has been 4 months since I last looked at this and have this working now, with a few caveats ...

nightwatch v1.5.0 geckodriver v1.20.0 selenium-server v3.141.59

Pieras2 commented 3 years ago

Tnx, I will try

Pieras2 commented 3 years ago

It works for me on both firefox and chrome when I provide list of keys in () not in [].

Tnx for your hints.

czw., 3 gru 2020, 16:44 użytkownik kretschmannj notifications@github.com napisał:

It has been 4 months since I last looked at this and maybe somewhere along the way it has been fixed as I have this working now, with a caveat ...

// this only works with selenium-server; it doesn't work with webdriver (geckodriver) sendKeys('xpath', "//input[@id='firstName']", [this.api.Keys.SHIFT, this.api.Keys.TAB, this.api.Keys.DOWN_ARROW, this.api.Keys.ENTER]) // this works with both webdriver and selenium-server sendKeys('xpath', "//input[@id='firstName']", this.api.Keys.SHIFT + this.api.Keys.TAB + this.api.Keys.DOWN_ARROW + this.api.Keys.ENTER)

I'm running this through Nightwatch and I'm using the nightwatch.conf.js file to switch between the in-built webdriver that uses the geckodriver downloaded to the project vs using the selenium-server downloaded to the project.

nightwatch v1.5.0 geckodriver v1.20.0 selenium-server v3.141.59

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/nightwatchjs/nightwatch/issues/2468#issuecomment-738089219, or unsubscribe https://github.com/notifications/unsubscribe-auth/AMUVMH552SOCPRKZ5UN5QL3SS6W6NANCNFSM4PXZZCLA .

artem-leandata commented 3 years ago

i was able to solve the problem in nightwatch.js by using following method:


this.setValue('@searchField', poolName, () => {
        this.api.keys([this.api.Keys.DOWN_ARROW, this.api.Keys.DOWN_ARROW, this.api.Keys.ENTER]);
      });
H3RSKO commented 3 years ago

I was able to solve this problem by passing the keycodes to a browser.setValue.

See here for my comment on a previous issue.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had any recent activity. If possible, please retry using the latest Nightwatch version and update the issue with any relevant details. If no further activity occurs, it will be closed. Thank you for your contribution.