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

Getting Wrong XPath/CSS Selector Type #142

Closed
allen-cook opened this issue Apr 24, 2014 · 4 comments
Closed

Getting Wrong XPath/CSS Selector Type #142

allen-cook opened this issue Apr 24, 2014 · 4 comments
Labels

Comments

@allen-cook
Copy link

When using .useXpath() and .useCss() I'm seeing the incorrect locator strategy used (or at least not what I'm expecting)

// custom command
browser.useXpath()      .waitForElementVisible("//span[contains(@testid,'refresh')]",1000)
.useCss().click("[testid='refresh']");

browser.useXpath().waitForElementVisible("//span[text()='"+appName+"']",1000);
// back in main test
browser.useXpath().click("//span[text()='"+myAppName+"']")
.useCss().waitForElementVisible('.manager-panels.transitioned. .appEditor.focused-app',1000);

I'm seeing various errors depending on what order I run these in. The first two are in a custom command and the last is in the main test. Right now, it's trying to use the "testid='refresh'" as an XPath locator.

@allen-cook
Copy link
Author

If I change the first command to be consistently css, then the second command tries to execute as css

// custom command
browser.waitForElementVisible("[testid='refresh']",1000)
.click("[testid='refresh']");

browser.useXpath().waitForElementVisible("//span[text()='"+appName+"']",1000);

// back in main test
browser.useXpath().click("//span[text()='"+myAppName+"']")
.useCss().waitForElementVisible('.manager-panels.transitioned. .appEditor.focused-app',1000);

@beatfactor
Copy link
Member

this should have been fixed in e64e03b but it's not currently released in npm, it's going to be there soon.

@beatfactor beatfactor added the bug label Apr 24, 2014
@allen-cook
Copy link
Author

I updated to latest, however I think what I'm seeing is a timing issue with custom commands and the main test thread.

I've added the following line to the top of index.js where the useCss() and useXpath() functions are

  this.api = {
    capabilities : {},
    globals : {},
    sessionId : null,
    useXpath : function() {
      console.trace("USING XPATH");
      self.locateStrategy = 'xpath';
      return this;
    },
    useCss : function() {
      console.trace("USING CSS");
      self.locateStrategy = 'css selector';
      return this;
    }
  };

This is the output I'm getting

Trace: USING CSS
    at Object.Nightwatch.api.useCss (source_code/node_modules/nightwatch/lib/index.js:29:15)
    at Object.<anonymous> (source_code/tests/nightwatch/commands/createNewApp.js:9:11)
...
Trace: USING XPATH
    at Object.Nightwatch.api.useXpath (source_code/node_modules/nightwatch/lib/index.js:24:15)
    at Object.<anonymous> (source_code/tests/nightwatch/commands/createNewApp.js:13:11)
...
Trace: USING XPATH
    at Object.Nightwatch.api.useXpath (source_code/node_modules/nightwatch/lib/index.js:24:15)
    at source_code/tests/nightwatch/tests/SessionEditTest.js:21:13
...
Trace: USING CSS
    at Object.Nightwatch.api.useCss (source_code/node_modules/nightwatch/lib/index.js:29:15)
    at source_code/tests/nightwatch/tests/SessionEditTest.js:22:6
...
✔  Element <[testid='refresh']> was visible after 1445 milliseconds.
CLIENT LOCATE STRAT - css selector
There was an error while executing the Selenium command - enabling the --verbose option might offer more details.
invalid element state: Failed to execute 'querySelector' on 'Document': '//span[text()='Test App.3386480.9782244265']' is not a valid selector.

I'm seeing the useCss in SessionEditTest.js (the main test) get applied before the waitForElement is getting executed in createNewApp.js (the custom command)

@beatfactor
Copy link
Member

should work now.

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

No branches or pull requests

2 participants