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.78k stars 1.31k forks source link

Click() function doesnt work/fail with a css selector #2127

Closed amirGaouaou closed 4 years ago

amirGaouaou commented 5 years ago

Hi we're seeing an issue in our tests when we upgraded from Nightwatch 1.0.19 to 1.1.11.

We're getting a NoSuchElementError when we call .click(selector) us with a Page object selector in css that matches more than 1 item.

The error also happens when we put a CSS selector that matches with a unique item.

This command worked in previous versions and just started failling in 1.1.11

Page object selector

    userDetailLinks: {
      selector: '.users__table > tbody > tr > td:nth-child(1) > div > a'
    }

Code

'Step: Users': (browser) => {
  const users = browser.page.userspage();
  userspage.click('@userDetailLinks');
}

Error

  NoSuchElementError: An error occurred while running .click() command on <Element [name=@userDetailLinks]>:
       at <anonymous>
       at process._tickCallback (internal/process/next_tick.js:188:7)
   Testing if the URL contains "?tab=userdetails" in 1000 ms. - expected "?tab=userdetails" but got: "https://cloud.ibm.com/iam/users"
       at Object.Step: Users (/Users/amirgaouaouw/Documents/Cloud/IBMCloudE2E/e2etests/iam-ui_e2etests/access-management/test/ibmcloudcm-golden-thread/nightwatch-tests/iam-user-details.js:37:15)
  NoSuchElementError: An error occurred while running .click() command on <Element [name=@userDetailLinks]>:
       at <anonymous>
       at process._tickCallback (internal/process/next_tick.js:188:7)

Server version;

Thank you

beatfactor commented 5 years ago

See v1.1.12.

amirGaouaou commented 5 years ago

Hi @beatfactor

Unfortunately, it happens for us still with 1.1.12.

I noticed that the error still happens whether I put an xpath/css selector that identifies a unique element/multiple element inside a page object

But it doesnt happen when I put an xpath/css selector that identifies a unique element directly as an argument when calling click

amirGaouaou commented 5 years ago

Hi @beatfactor,

Is this being triaged or prioritized ? Thank you

jlee-locktonmylo commented 5 years ago

We are seeing the same issue on our Ubuntu Linux box as well. The same test works fine on my windows 10 machine:

Linux info: ChromeDriver 75.0.3770.8 Google Chrome 75.0.3770.90 Distributor ID: Ubuntu Description: Ubuntu 16.04.6 LTS Release: 16.04 Codename: xenial

Error: NoSuchElementError: Error while running "waitForElementVisible" command: Timed out while waiting for element "[id="referralGroup"] option[value=Onboarding]" with "css selector" to be present for 1000 milliseconds.

Command being run let fillForm = browser.page.referralForm.legalzoomReferralPO() fillForm .chooseReferralOnboarding()

Page Objects File: chooseReferralOnboarding: function () { return this.waitForElementVisible('@referralGroup', 1000) .click('@referralGroup') },

Identifier in PO file: referralGroup: { selector: '[id="referralGroup"] option[value=Onboarding]' },

I was just doing the click command from the test itself, I moved it into a funciton in the pageObject to see if that would fix it but it didn't.

jlee-locktonmylo commented 5 years ago

Just an update, my problems went away in linux + chrome when I made this change

use_legacy_jsonwire = true

Can someone help me understand why this is just affecting my linux chrome env?

webdriver: { start_process: true, server_path: './node_modules/chromedriver/lib/chromedriver/chromedriver', use_legacy_jsonwire: true, port: 9515 },

vlad-vinogradov commented 5 years ago

@jlee-locktonmylo

Can someone help me understand ...

It depends on chromedriver's version. See #2118

amirGaouaou commented 5 years ago

image

In the example here. In 1.0.19 => The click works and the test passes In 1.1.13 => The click fails and throws an error

stale[bot] commented 4 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.