在查询选择器中传递多个属性

Pass multiple attributes in query selector

我试图在我的人偶测试中使用以下两个查询选择器访问下面突出显示的元素。两者都不工作。

document.querySelector('div[class="slick-cell l1 r1"][title="08787878787001"]')

document.querySelector('div[title="08787878787001"]')

HTML :

仍然没有结果。我不能在属性之间放置逗号,因为它认为是“OR”并让我得到不同的元素。

有什么解决办法?

正确的选择器是:

document.querySelector('div.slick-cell.l1.r1')

您可以阅读更多关于选择器的内容 here

选择器没有这样的文本匹配。如果您尝试根据文本匹配它,请使用 XPath:

$x('//div[@class="slick-cell l1 r1" and @title][text()="08787878787001"]')