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

I.click using inner text does not working properly #647

Closed
Jotohanes opened this Issue Aug 3, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@Jotohanes

Jotohanes commented Aug 3, 2017

What are you trying to achieve?

I would like to click certain text in particular locator.

What do you get instead?

Clickable element JETZT KAUFEN inside .mscom-link.c-call-to-action.c-glyph was not found by text|CSS|XPath

I am pretty sure it was not the case on previous version of codeceptjs since I got this error recently after I update my codeceptjs.

  Clickable element JETZT KAUFEN inside .mscom-link.c-call-to-action.c-glyph was not found by text|CSS|XPath

Provide test source code if related

Scenario('test something', (I) => {

    I.amOnPage('https://www.microsoft.com/de-de/');
    I.waitForVisible('.mscom-link.c-call-to-action.c-glyph');
    I.click('JETZT KAUFEN','.mscom-link.c-call-to-action.c-glyph');

});
    

Details

  • CodeceptJS version: 1.0.0
  • NodeJS Version: 6.11.0
  • Operating System: Windows 7 Pro, 2009
  • WebDriverIO
  • Configuration file:
{
  "tests": "./*_test.js",
  "timeout": 10000,
  "output": "./output",
  "helpers": {
    "WebDriverIO": {
      "url": "http://localhost",
      "browser": "chrome"
    }
  },
  "include": {
    "I": "./steps_file.js"
  },
  "bootstrap": false,
  "mocha": {},
  "name": "test"
}

@Jotohanes Jotohanes changed the title from I.click using inner text not working properly to I.click using inner text does not working properly Aug 3, 2017

@APshenkin

This comment has been minimized.

Show comment
Hide comment
@APshenkin

APshenkin Aug 7, 2017

Collaborator

@Jotohanes so, the problem is that .mscom-link.c-call-to-action.c-glyph element is link itself with necessary text. When we add context in click, then the flow is:

  1. Recieve all elements context and get first of them.
  2. Get first inner element with text, using these locators:
let narrowLocator = xpathLocator.combine([
    `.//a[normalize-space(.)=${literal}]`,
    `.//button[normalize-space(.)=${literal}]`,
    `.//a/img[normalize-space(@alt)=${literal}]/ancestor::a`,
    `.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][normalize-space(@value)=${literal}]`
  ]);

or
let wideLocator = xpathLocator.combine([
      `.//a[./@href][((contains(normalize-space(string(.)), ${literal})) or .//img[contains(./@alt, ${literal})])]`,
      `.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][contains(./@value, ${literal})]`,
      `.//input[./@type = 'image'][contains(./@alt, ${literal})]`,
      `.//button[contains(normalize-space(string(.)), ${literal})]`,
      `.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][./@name = ${literal}]`,
      `.//button[./@name = ${literal}]`
    ]);

So, when you set .mscom-link.c-call-to-action.c-glyph element, there is no inner elements. because of this we can't find elements with necessary text

I fixed this issue, but we need @DavertMik review to merge it

Collaborator

APshenkin commented Aug 7, 2017

@Jotohanes so, the problem is that .mscom-link.c-call-to-action.c-glyph element is link itself with necessary text. When we add context in click, then the flow is:

  1. Recieve all elements context and get first of them.
  2. Get first inner element with text, using these locators:
let narrowLocator = xpathLocator.combine([
    `.//a[normalize-space(.)=${literal}]`,
    `.//button[normalize-space(.)=${literal}]`,
    `.//a/img[normalize-space(@alt)=${literal}]/ancestor::a`,
    `.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][normalize-space(@value)=${literal}]`
  ]);

or
let wideLocator = xpathLocator.combine([
      `.//a[./@href][((contains(normalize-space(string(.)), ${literal})) or .//img[contains(./@alt, ${literal})])]`,
      `.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][contains(./@value, ${literal})]`,
      `.//input[./@type = 'image'][contains(./@alt, ${literal})]`,
      `.//button[contains(normalize-space(string(.)), ${literal})]`,
      `.//input[./@type = 'submit' or ./@type = 'image' or ./@type = 'button'][./@name = ${literal}]`,
      `.//button[./@name = ${literal}]`
    ]);

So, when you set .mscom-link.c-call-to-action.c-glyph element, there is no inner elements. because of this we can't find elements with necessary text

I fixed this issue, but we need @DavertMik review to merge it

@Jotohanes

This comment has been minimized.

Show comment
Hide comment
@Jotohanes

Jotohanes Aug 9, 2017

Hello, thanks for fixing the problem. Thus, I will update it and let you know if there is another problem regarding to the issue.

Jotohanes commented Aug 9, 2017

Hello, thanks for fixing the problem. Thus, I will update it and let you know if there is another problem regarding to the issue.

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