通过黄瓜处理 xpath 中的 <br> 标记

Handling <br> tag in xpath through cucumber

我正在使用带有 Selenide 框架的 Cucumber,我在 Cucumber 的 regression.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 函数中设置一个 Xpath,使其在 <br> 标记是否存在的情况下通过?

您可以评估 header:

的字符串表示,而不是评估 child 文本节点 (text())
//h1[normalize-space()='" + name + "']