我正在尝试使用xpath在Mozilla浏览器中识别WebElement
。以下是html代码:
<div id="address-book" class="grid-12" style="display:none;">
<!-- END ADDRESS BOOK -->
<!-- BEGIN PAYMENT OPTIONS -->
<div id="paymentSection" class="grid-12 form-section">
<div class="grid-contentx">
<div class="hd header-container">
<h3>Payment Information</h3>
</div>
</div>
<!-- BEGIN: CC FORMS -->
<div class="grid-6">
我在页面对象工厂中写的相关xpath是:
@FindBy(xpath = "//*[@id='paymentSection']/div[1]/div/h3")
private WebElement paysection;
运行脚本后,我收到一条错误消息“无法识别元素”。如果要对已识别的xpath进行任何更正,请帮助我。
答案 0 :(得分:0)
在上述情况下,有很多xpaths
可以帮助您找到h3
,让我列出几个:
使用 id:
xpath = "//div[@id='paymentSection']//h3"
使用文字
xpath = "//h3[contains(.,'Payment Information')]"
使用类名:
xpath = "//div[@id='paymentSection']//div[@class='hd header-container']/h3"
结合使用 id 和类名:
xpath = "//div[@id='paymentSection' and @class='grid-12 form-section']//h3"