1

browser.useXpath.waitForElementVisible() seems to have problems with (class-)names containing whitespaces. My full classname is jstree-anchor jstree-clicked.

The following commands succeed:

browser.useXpath()
    .waitForElementVisible('//a[contains(@class, "jstree-anchor")][text()="' + name + '"]', 5000)
    .waitForElementVisible('//a[contains(@class, "jstree-clicked")][text()="' + name + '"]', 5000);

But these fail:

browser.useXpath()
    .waitForElementVisible('//a[contains(@class, "jstree-anchor jstree-clicked")][text()="' + name + '"]', 5000);
browser.useXpath()
    .waitForElementVisible('//a[@class="jstree-anchor jstree-clicked"][text()="' + name + '"]', 5000);

How do I handle such elements when I do have to check for the full class name?

Dale
  • 10,384
  • 21
  • 34
Munchkin
  • 4,528
  • 7
  • 45
  • 93
  • 2
    They are two separate class' if you wish to usex xpath to find a element with more than one class see https://stackoverflow.com/questions/21713280/find-div-element-by-multiple-class-names – Alessi 42 May 23 '17 at 11:30
  • quote from [w3schools](https://www.w3schools.com/jsref/prop_html_classname.asp): "Specifies the class name of an element. To apply multiple classes, separate them with spaces, like 'test demo'". So **there are no class names with spaces in them**, because spaces are used to separate those... solution: use properly constructed class names. – garglblarg May 23 '17 at 11:43
  • @Alessi42 The accepted answer there suggests to use exactly the same way I already tried (but failed): `waitForElementVisible('//a[@class="jstree-anchor jstree-clicked"]', 5000);` (I also tried with single quotes) – Munchkin May 23 '17 at 12:13

2 Answers2

0

Have you considered simply spliting up the contain?

browser.useXpath()
    .waitForElementVisible('//a[contains(@class, "jstree-anchor jstree-clicked")][text()="' + name + '"]', 5000);

would become:

browser.useXpath()
        .waitForElementVisible('//a[contains(@class, "jstree-anchor") and contains(@class, "jstree-clicked")][text()="' + name + '"]', 5000);
  • Sorry for not being precise in my question, I want to match exactly `jstree-anchor jstree-clicked` - your answer would also match sth. like `jstree-anchor jstree-clicked foo bar` – Munchkin May 23 '17 at 12:40
0

you can try following which uses cssSelectors:

 browser.useCss()
.waitForElementVisible('a.jstree-anchor.jstree-clicked[innertext="' + name + '"]', 5000);
Kushal Bhalaik
  • 3,349
  • 5
  • 23
  • 46
  • It only works when I don't check for the text: `browser.useCss().waitForElementVisible('a.jstree-anchor.jstree-clicked', 5000);` But I need to check the text. The html looks like this: `MyText` – Munchkin May 23 '17 at 13:32
  • works neither. It looks like it isn't possible yet via css selector: [Unfortunately there isn't a CSS selector that matches on the text of an element.](https://stackoverflow.com/a/42567761/1654763) – Munchkin May 23 '17 at 14:38