簡體   English   中英

具有兩個內部文本的 web 元素的 xpath

[英]xpath for an webelement which is having two inner text

我正在使用版本 4.1.4 的 selenium-java。 我正在嘗試從 UI 中讀取文本。HTML 代碼如下所示。

<div class="css-1o5t8tj">
     <span class="MuiTypography-root MuiTypography-caption css-wev09c">
         "$"
         "10.99"
     </span>
     <span class="MuiTypography-root MuiTypography-caption css-1kcldpk">
         "$"
         "13.44"
     </span>
 </div>

我用下面的代碼來閱讀文本

 String txt = driver.findElement(By.xpath("//div[@class='css-1o5t8tj']//span[1]")).getText() ;  

但它返回空字符串。實際上我在這里期待 String txt = "$10.99"。 有沒有辦法得到這個文本? 提前致謝。

試試這個 xpath -

(//div/span[contains(@class='MuiTypography-root MuiTypography-caption')])[1]

暫無
暫無

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

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