[英]xpath for an webelement which is having two inner text
I am using selenium-java with version 4.1.4.我正在使用版本 4.1.4 的 selenium-java。 I am trying to read a text from the UI.The HTML code is given below.
我正在尝试从 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>
I have used below code to read the text我用下面的代码来阅读文本
String txt = driver.findElement(By.xpath("//div[@class='css-1o5t8tj']//span[1]")).getText() ;
But it returns empty string.Actually here i am expecting the String txt = "$10.99".但它返回空字符串。实际上我在这里期待 String txt = "$10.99"。 Is there any way to get this text?
有没有办法得到这个文本? Thanks in advance.
提前致谢。
试试这个 xpath -
(//div/span[contains(@class='MuiTypography-root MuiTypography-caption')])[1]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.