【发布时间】:2017-11-27 01:12:46
【问题描述】:
我有html代码:
<div class="formCaptionContainer fill-width" data-dyn-bind="sizing: { width: $dyn.layout.Size.available }">
<h1 class="formCaption" data-dyn-bind="text: $data.Caption, click: $data.GoGridView">Expense report for Aditi Mehta - GS1-000282, testing2</h1>
<h2 class="formCaption-context" data-dyn-bind="text: $data.ParentTitleFields">Aditi Mehta : GS1-000282</h2>
</div>
我想从 /h1 标签获取 Aditi Mehta - GS1-000282, testing2 的价值费用报告
有人知道怎么做吗?
我试过了:
By.xpath(".//div[@class='formCaption']/h1";
上面显示没有找到元素
By.className("formCaption");
上面显示空白数据
By.xpath(".//*[@class='formCaption']/h1");
上面显示没有找到元素
【问题讨论】:
-
试试这个 xpath。 "//h1[@class='formCaptain']"
-
我厌倦了上面的,显示'没有找到这样的元素'
-
您可以尝试添加一些等待和检查吗?
-
是的,我也这样做了。但要么我没有找到这样的元素,要么空白数据即将到来。
-
空白文本来意味着 xpath 是正确的。这打印了什么。 driver.findElement(By.xpath("//h1[@class='formCaptain']")).getText();