Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expect.element(...).to.not.to.present fails when using index for the selector #3810

Open
reallymello opened this issue Jul 14, 2023 · 1 comment · May be fixed by #4071
Open

expect.element(...).to.not.to.present fails when using index for the selector #3810

reallymello opened this issue Jul 14, 2023 · 1 comment · May be fixed by #4071
Labels

Comments

@reallymello
Copy link
Contributor

Description of the bug/issue

When I attempt to assert a specific index of an element is not present and the element is not present I except the assertion to pass, but instead I receive error

  Error

   Element Element [name=@additionalInterestRowDetail[1]] not found. An element could not be located on the page using the given search parameters.

  ✖ NightwatchAssertError

   Expected element @additionalInterestRowDetail <[fieldref="AdditionalOtherInterestInput.Description"]> to not be present - element was not found - expected "not present" but got: "error while locating the element" (10ms)

Steps to reproduce

Use .expect.element({selector: 'some selector', index: 1}).to.not.be.present in a test where the selector is present on the page, but only one instance of it is present...so there would be an index 0 but not index 1. The scenario I am trying to verify is that there aren't more than one of this particular item on the page.

myPageObject.expect.element({selector: '@validSelectorAlias',
index: 1}).to.not.be.present;

Instead of passing the check that it is not present the test fails because it can't locate that selector at index 1. This works fine without using an index.

Sample test

myPageObject.expect.element({selector: '@validSelectorAlias',
index: 1}).to.not.be.present;

Command to run

n/a

Verbose Output

→ Running command: expect.element ({name, __index, __selector, locateStrategy, pseudoSelector, parent, resolvedElement, abortOnFailure, suppressNotFoundErrors, timeout...})

   Request POST /session/176def76257ef8a44ce7db8a5fcb4db0/elements 

   {

     using: 'css selector',

     value: '[fieldref="AdditionalOtherInterestInput.Description"]'

  }

   Response 200 POST /session/176def76257ef8a44ce7db8a5fcb4db0/elements (6ms)

   {

     value: [

       {

         'element-6066-11e4-a52e-4f735466cecf': '30D0DFA34670C2A3575ECD64283B90F2_element_205'

       }

     ]

  }

  Error

   Element Element [name=@additionalInterestRowDetail[1]] not found. An element could not be located on the page using the given search parameters.

  ✖ NightwatchAssertError

   Expected element @additionalInterestRowDetail <[fieldref="AdditionalOtherInterestInput.Description"]> to not be present - element was not found - expected "not present" but got: "error while locating the element" (12ms)

Nightwatch Configuration

n/a

Nightwatch.js Version

2.6.21

Node Version

18

Browser

Chrome 114

Operating System

Windows 11

Additional Information

No response

@dikwickley
Copy link
Contributor

A very weird observation

this gives the same Element .hero__title not found. An element could not be located on the page using the given search parameters. error

describe('Ecosia.org Demo', function() {
  before(browser => {
    browser
      .navigateTo('https://www.ecosia.org/');
  });

  it('Demo test ecosia.org', async function(browser) {
    const element = browser
      .waitForElementVisible('body')
      .expect.element({selector: '.hero__title', index: 1})



    element.to.not.be.present;
  });

  after(browser => browser.end());
});

but just adding a console log, makes it pass

describe('Ecosia.org Demo', function() {
  before(browser => {
    browser
      .navigateTo('https://www.ecosia.org/');
  });

  it('Demo test ecosia.org', async function(browser) {
    const element = browser
      .waitForElementVisible('body')
      .expect.element({selector: '.hero__title', index: 1})

    console.log(await element)

    element.to.not.be.present;
  });

  after(browser => browser.end());

investigating more on this...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants