无法找到带有空格的classname

时间:2017-05-23 11:28:07

标签: javascript css selenium nightwatch.js

browser.useXpath.waitForElementVisible()似乎与包含空格的(类)名称有问题。我的完整班级名称为jstree-anchor jstree-clicked

以下命令成功:

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

但这些失败了:

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);

当我必须检查完整的班级名称时,如何处理这些元素?

2 个答案:

答案 0 :(得分:0)

您是否考虑过简单地拆分包含?

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

会变成:

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

答案 1 :(得分:0)

您可以尝试使用cssSelectors:

 browser.useCss()
.waitForElementVisible('a.jstree-anchor.jstree-clicked[innertext="' + name + '"]', 5000);