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

element() ignores use_xpath #3033

Closed
chrisvanrun opened this issue Feb 7, 2022 · 4 comments · Fixed by #3147
Closed

element() ignores use_xpath #3033

chrisvanrun opened this issue Feb 7, 2022 · 4 comments · Fixed by #3147

Comments

@chrisvanrun
Copy link

Describe the bug

Using the new global element() will default to css_selector as locate strategy, even if use_xpath is set to true in configuration.

With for example:

module.exports = {
  sampleTest: function(browser) {
    const el = element('//body');
    console.log('use_xpath =', browser.options.use_xpath);
    console.log('locateStrategy =', el.locateStrategy);
  }
}

It outputs:

use_xpath = true
locateStrategy = css selector

Configuration

nightwatch.conf.js

module.exports = {

  src_folders: ['nightwatch/tests'],
  page_objects_path: 'nightwatch/pages',

  output_timestamp: true,
  live_output: true,
  webdriver: {
    start_process: true,
  },

  use_xpath: true,

  test_settings: {
    default: {
      launch_url: 'http://localhost:8888/cirrus',

      desiredCapabilities: {
        browserName: 'chrome',
        'goog:chromeOptions': {
          w3c: true,
        },

        globals: {
          waitForConditionTimeout: 10000,
        },
      },
      screenshots: {
        enabled: false,
        path: './screenshots',
        on_error: true,
        on_failure: true,
      },
    },
  },

  // Parallel settings
  parallel_process_delay: 200,
  test_workers: {
    enabled: false,
    workers: 4,
  },
};

Your Environment

Executable Version
nightwatch --version 2.0.2
@beatfactor
Copy link
Member

how about if you do:

element({
  selector: '//body',
  locateStrategy: 'xpath'
});

you can also use the by() class from selenium, which is available as a global in Nightwatch as well.

element(by.xpath('//body'))

@chrisvanrun
Copy link
Author

Thanks @beatfactor! Both work fine, and have actually been employed to circumvent this bug. However, for a clean suite it's nice to be able to have options where one can provide only one selector string to adhere to the global default.

@beatfactor
Copy link
Member

I agree, I was just making sure that there are workarounds until we fix the issue.

@aakash3771
Copy link

Same issue is with elements() too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
4 participants