Javascript 找不到带空格的类名

Javascript 找不到带空格的类名,javascript,css,selenium,nightwatch.js,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[

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

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

您是否考虑过简单地拆分contain

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

您可以尝试使用CSS选择器执行以下操作:

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

如果您希望使用X xpath查找包含多个类的元素,请参阅引文:“指定元素的类名。要应用多个类,请使用空格分隔它们,如“test demo”。所以没有带空格的类名,因为空格用来分隔那些。。。解决方案:使用正确构造的类名。@ALESI42接受的答案建议使用与我已经尝试过(但失败)的完全相同的方式:
waitForElementVisible(“//a[@class=“jstree anchor jstree clicked”]”,5000)
(我也尝试了单引号)很抱歉我的问题不准确,我想精确匹配
jstree-anchor-jstree-clicked
-你的答案也会匹配一些东西,比如
jstree-anchor-jstree-clicked-foo-bar
它只在我不检查文本时起作用:
browser.useCss().waitForElementVisible('a.jstree-anchor.jstree clicked',5000);
但我需要检查文本。html如下所示:
MyText
都不起作用。看起来还不可能通过css选择器: