我正在使用带有Selenide框架的黄瓜,在黄瓜的returnion.feature文件中有以下步骤:
Then Check if has a section labelled "Foo bar foo bar"
在Steps.java文件中,我有:
@Then("^Check if has a section labelled \"([^\"]*)\"$")
public void checkThatHomePageHassectionLabelled(String arg0) throws Throwable {
servicesSectionCheck(arg0);
}
我想检查一下:
public static void servicesSectionCheck(String name) {
$(byXpath("//h1[(text()='" + name + "')]")).shouldBe(visible);
}
问题有时是当浏览器较小时(RWD问题),HTML看起来像
<div id="services" class="page_section row">
<input type="hidden" id="Count1" value="4">
<input type="hidden" id="Count2" value="2">
<input type="hidden" id="Count3" value="10">
<input type="hidden" id="loadMoreServicesURL" value="anURLhere">
<input type="hidden" id="portletNamespace" value="_serviceslist_INSTANCE_t8TJHYdgnwCu_">
<div class="col-12 desktop-padding">
<div class="d-none d-sm-block margin-top-50"></div>
<h1 class="text-center d-none d-sm-block">Foo bar <br> foo bar</h1>
<div class="d-none d-sm-block margin-bottom-40"></div>(...)
有时
<h1 class="text-center d-none d-sm-block">Foo bar foo bar</h1>
无论是否显示servicesSectionCheck
标签,如何在<br>
函数中设置Xpath通过?
答案 0 :(得分:1)
您可以评估标头的字符串表示形式,而不是评估子文本节点(text()
)
//h1[normalize-space()='" + name + "']