英文:
Selenium: is there any way to find an element that has nothing inside?
问题
I'd like to find an element that has nothing inside.
For example:
<div class="top">
selection:
<b></b>
</div>
It displays like this:
selection:
In this HTML code, <b></b>
has nothing inside. But for testing purposes, I want to find it without text inside.
I tried
findElement(By.xpath("//div[contains(@class,'top')]/b[not(node())]")
but it didn't return anything.
Is there a way to locate <b></b>
?
英文:
I'd like to find an element that has nothing inside.
For example:
<div class="top">
selection:
<b></b>
</div>
It displays like this:
selection:
In this HTML code, <b></b>
has nothing inside. But for testing purpose, I want to find it without text inside.
I tried
findElement(By.xpath("//div[contains(@class,'top')]/b[text()=='']")
but it didn't return anything.
Is there a way to locate <b></b>
?
答案1
得分: 1
Remove the text()
matcher.
//div[contains(@class,'top')]/b
Will match the <b>
Alternatively:
//div[contains(@class,'top')]/b[not(text())]
英文:
Remove the text()
matcher.
//div[contains(@class,'top')]/b
Will match the <b>
Alternatively:
//div[contains(@class,'top')]/b[not(text())]
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论