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

Calling cssContainingText to search for subelements results in "Invalid locator" error #948

Closed
PaddyMann opened this issue Jun 19, 2014 · 4 comments

Comments

@PaddyMann
Copy link

#52 discusses chaining findElement to find child elements.

As discussed in that issue, I can see that this works:

 ptor.findElement(protractor.By.tagName('tbody')).findElements(protractor.By.tagName('tr')).then(function(rows){
    expect(rows.length).toBe(10);
});

It also works to call protractor.By.cssContainingText in place of the first locator.

But if I change it to:

 ptor.findElement(protractor.By.tagName('tbody')).findElements(protractor.By.cssContainingText('tr','my text')).then(function(rows){
    expect(rows.length).toBe(10);
});

then I get "TypeError: Invalid locator".

Is this expected behaviour? Would be great to be able to use cssContainingText in this way.

@elgalu
Copy link
Contributor

elgalu commented Jun 19, 2014

Why not just:

expect(element.all(by.cssContainingText('tbody tr','my text')).
  count()).toBe(10);

Or if your prefer then because you need to do some more stuff with the array:

element.all(by.cssContainingText('tbody tr','my text')).then(function(rows) {
  expect(rows.length).toBe(10);
});

@PaddyMann
Copy link
Author

The above was a simple example.

In practice:

  • I have a survey page object
  • This contains questions, also represented as page objects
  • Questions can have multiple dimensions, also represented as page objects.

So I would want to call:

var eleQuestion =  this.findElement(this.by.cssContainingText('tbody.question', 'Ability to lead a team'));

And then in the question page object:

var eleDimension =  eleQuestion.findElement(this.by.cssContainingText('.dimension', 'Current performance'));

Where this.element represents the question returned in the first code block.

This can't be represented with a single query as I'm doing a 'contains' at both level, and I want to split it out to better structure the page objects.

An aside: I'd actually prefer to do an exact match on the trimmed value of element (rather than a contains), but that's a separate question/issue that I guess will lead to me extending webdriver. I would still like to be able to make use of cssContainingText as shown in the example above.

@hankduan
Copy link
Contributor

We've moved away from webdriver's use of FindElement/FindElements to element()/elements.all() to better support page objects:
i.e. element(xxx).element(yyy).all(zzz) or `element.all(xxx)

If you change all your FindElements, everything should work as intended.

Also, you don't need to call then anymore (and it's suggested that you don't, although it will work either way).
i.e. element(xxx).click() instead of element(xxx).then(function(elem) {elem.click();}) or ptor.findElement(xxx).then(function(elem) {elem.click();})

@hankduan hankduan self-assigned this Jun 19, 2014
@PaddyMann
Copy link
Author

Thanks @hankduan - I got it working in this way and will close the issue.

@hankduan hankduan removed their assignment Nov 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants