簡體   English   中英

如何使用xpath訪問特定的子div? (Selenium Java)

[英]How to access a specific child div using xpath? (Selenium Java)

我有以下HTML代碼:

<div class="panel">
    <div class = "heading">
        <span class="wName">Name</span>
        <div class="foo1" style="display: none;"></div>
        <div class="foo2" style="display: none;"></div>
    </div>
</div>

我已經找到了元素面板,我試圖測試foo2何時沒有出現以下代碼行:

if (panel.findElement(By.xpath("../div[@class='foo2']")).getCssValue("display").equals("none"))

我不確定為什么這不會正確檢索元素。

你的XPath錯了! ..意思是“父母”。 單點. 相對於當前位置而言。

嘗試: panel.findElement(By.xpath(".//div[@class='foo2']")

你怎么用后代

panel.findElement(By.xpath("//div[@class='panel']/descendant::div[@class='foo2']"));

來源http://www.caucho.com/resin-3.1/doc/xpath.xtp#descendant

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM