CodeceptJS icon indicating copy to clipboard operation
CodeceptJS copied to clipboard

Nested locator with first()

Open TempleOfTemplar opened this issue 6 years ago • 1 comments

What are you trying to achieve?

Get first element with attr tid="device" inside block with attr tid="requesting-devices-list", using following selector: locate("[tid=requesting-devices-list] [tid=device]").first()

  • (also i tried to use: locate({tid: 'device'}).inside({tid: 'requesting-devices-list'}).first() , cause i have custom selector "tid=..." in config)

What do you get instead?

Error: 
XPath with round brackets is not possible here! May be a nested locator with at() last() or first() causes this error.
locate("[tid=requesting-devices-list] [tid=device]").first()

Details

  • CodeceptJS version: 2.3.6.
  • NodeJS Version: 12.1.0
  • Operating System: Windows
  • puppeteer 2.0.0
  • Configuration file:
exports.config = {
  tests: './testing/tests/*_test.js',
  output: './testing/output',
  helpers: {
    Puppeteer: {
      url: 'https://localhost:4204',
      show: true,
      restart: false,
      waitForNavigation: ["domcontentloaded", "networkidle2"]
    },
    MockRequest: {},
  },
  include: {
    I: './testing/steps_file.js',
    deviceManagerPage: './testing/pages/DeviceManagerPagePo.js',

  },
  bootstrap: function (done) {
    codeceptjs.locator.addFilter((providedLocator, locatorObj) => {
      if (providedLocator.tid) {
        locatorObj.type = 'css';
        locatorObj.value = `*[tid="${providedLocator.tid}"]`;
      }
    });
    done();
  },
  mocha: {},
  name: 'TestApp',
  translation: 'ru-RU'
};

TempleOfTemplar avatar Dec 02 '19 08:12 TempleOfTemplar

This would be really useful to support nested locators

nicostubi avatar Sep 10 '22 13:09 nicostubi

agreed. I try go generate .//tr[position()=1]/td/button[class="button"] and got this error

esteban-serfe avatar Nov 25 '22 22:11 esteban-serfe

Closed for now! Feel free to reopen if you still encounter the issue with latest version and would be nice to provide a sample code to reproduce the issue.

kobenguyent avatar Oct 23 '23 12:10 kobenguyent