Handling tag in xpath through cucumber












1















I'm using cucumber with Selenide frameworks, I have the following step in cucumber's regression.feature file:



Then Check if has a section labelled "Foo bar foo bar"


In Steps.java file I have:



@Then("^Check if has a section labelled "([^"]*)"$")
public void checkThatHomePageHassectionLabelled(String arg0) throws Throwable {
servicesSectionCheck(arg0);
}


And I would like to check if:



public static void servicesSectionCheck(String name) {
$(byXpath("//h1[(text()='" + name + "')]")).shouldBe(visible);
}


The problem is sometimes when the browser is smaller (RWD issue), the HTML is looking like



<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>(...)


And sometimes



<h1 class="text-center d-none d-sm-block">Foo bar foo bar</h1>


How can I set an Xpath in servicesSectionCheck function to pass despite if <br> tag is presented or not?










share|improve this question

























  • "//h1/(text()='" + name + "')]" doesn't seem to be valid XPath... Did you mean "//h1[(text()='" + name + "')]"?

    – Andersson
    Nov 21 '18 at 9:54











  • Yes, wrong copied, sorry :D

    – Michal
    Nov 21 '18 at 9:55
















1















I'm using cucumber with Selenide frameworks, I have the following step in cucumber's regression.feature file:



Then Check if has a section labelled "Foo bar foo bar"


In Steps.java file I have:



@Then("^Check if has a section labelled "([^"]*)"$")
public void checkThatHomePageHassectionLabelled(String arg0) throws Throwable {
servicesSectionCheck(arg0);
}


And I would like to check if:



public static void servicesSectionCheck(String name) {
$(byXpath("//h1[(text()='" + name + "')]")).shouldBe(visible);
}


The problem is sometimes when the browser is smaller (RWD issue), the HTML is looking like



<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>(...)


And sometimes



<h1 class="text-center d-none d-sm-block">Foo bar foo bar</h1>


How can I set an Xpath in servicesSectionCheck function to pass despite if <br> tag is presented or not?










share|improve this question

























  • "//h1/(text()='" + name + "')]" doesn't seem to be valid XPath... Did you mean "//h1[(text()='" + name + "')]"?

    – Andersson
    Nov 21 '18 at 9:54











  • Yes, wrong copied, sorry :D

    – Michal
    Nov 21 '18 at 9:55














1












1








1








I'm using cucumber with Selenide frameworks, I have the following step in cucumber's regression.feature file:



Then Check if has a section labelled "Foo bar foo bar"


In Steps.java file I have:



@Then("^Check if has a section labelled "([^"]*)"$")
public void checkThatHomePageHassectionLabelled(String arg0) throws Throwable {
servicesSectionCheck(arg0);
}


And I would like to check if:



public static void servicesSectionCheck(String name) {
$(byXpath("//h1[(text()='" + name + "')]")).shouldBe(visible);
}


The problem is sometimes when the browser is smaller (RWD issue), the HTML is looking like



<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>(...)


And sometimes



<h1 class="text-center d-none d-sm-block">Foo bar foo bar</h1>


How can I set an Xpath in servicesSectionCheck function to pass despite if <br> tag is presented or not?










share|improve this question
















I'm using cucumber with Selenide frameworks, I have the following step in cucumber's regression.feature file:



Then Check if has a section labelled "Foo bar foo bar"


In Steps.java file I have:



@Then("^Check if has a section labelled "([^"]*)"$")
public void checkThatHomePageHassectionLabelled(String arg0) throws Throwable {
servicesSectionCheck(arg0);
}


And I would like to check if:



public static void servicesSectionCheck(String name) {
$(byXpath("//h1[(text()='" + name + "')]")).shouldBe(visible);
}


The problem is sometimes when the browser is smaller (RWD issue), the HTML is looking like



<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>(...)


And sometimes



<h1 class="text-center d-none d-sm-block">Foo bar foo bar</h1>


How can I set an Xpath in servicesSectionCheck function to pass despite if <br> tag is presented or not?







xpath cucumber selenide






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 10:27







Michal

















asked Nov 21 '18 at 9:44









MichalMichal

96214




96214













  • "//h1/(text()='" + name + "')]" doesn't seem to be valid XPath... Did you mean "//h1[(text()='" + name + "')]"?

    – Andersson
    Nov 21 '18 at 9:54











  • Yes, wrong copied, sorry :D

    – Michal
    Nov 21 '18 at 9:55



















  • "//h1/(text()='" + name + "')]" doesn't seem to be valid XPath... Did you mean "//h1[(text()='" + name + "')]"?

    – Andersson
    Nov 21 '18 at 9:54











  • Yes, wrong copied, sorry :D

    – Michal
    Nov 21 '18 at 9:55

















"//h1/(text()='" + name + "')]" doesn't seem to be valid XPath... Did you mean "//h1[(text()='" + name + "')]"?

– Andersson
Nov 21 '18 at 9:54





"//h1/(text()='" + name + "')]" doesn't seem to be valid XPath... Did you mean "//h1[(text()='" + name + "')]"?

– Andersson
Nov 21 '18 at 9:54













Yes, wrong copied, sorry :D

– Michal
Nov 21 '18 at 9:55





Yes, wrong copied, sorry :D

– Michal
Nov 21 '18 at 9:55












1 Answer
1






active

oldest

votes


















1














Instead of evaluating child text node (text()) you can evaluate string representation of header:



//h1[normalize-space()='" + name + "']





share|improve this answer
























  • Following xpath doesn't work, but I'm looking in this way, thanks :)

    – Michal
    Nov 21 '18 at 10:11











  • @Michal It should work with the provided HTML sample... Can you update your HTML sample if your simplified code source doesn't look like the real one? Also check whether your name variable is actually "Foo bar foo bar", but not "Foo barfoo bar" or something else

    – Andersson
    Nov 21 '18 at 10:15













  • Added. I spotted that this is Foo bar foo bar, but in HTML there's Foo bar <br> foo bar, but adding an additional space in the "Then" line changed nothing

    – Michal
    Nov 21 '18 at 10:29











  • And btw, the first option (as described in my question) is 99% times - I think about focusing overcoming this <br> tag first, then think about the second issue, if needed

    – Michal
    Nov 21 '18 at 10:36






  • 1





    @Michal this looks more complicated , but shuold cover all 3 cases (including the one before question was modified): //h1[starts-with(., "Foo bar") and normalize-space(substring-after(., "Foo bar"))="foo bar"]. With this XPath we can ignore <br> as well as spaces between 1st and 2nd text

    – Andersson
    Nov 21 '18 at 10:39













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409191%2fhandling-br-tag-in-xpath-through-cucumber%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Instead of evaluating child text node (text()) you can evaluate string representation of header:



//h1[normalize-space()='" + name + "']





share|improve this answer
























  • Following xpath doesn't work, but I'm looking in this way, thanks :)

    – Michal
    Nov 21 '18 at 10:11











  • @Michal It should work with the provided HTML sample... Can you update your HTML sample if your simplified code source doesn't look like the real one? Also check whether your name variable is actually "Foo bar foo bar", but not "Foo barfoo bar" or something else

    – Andersson
    Nov 21 '18 at 10:15













  • Added. I spotted that this is Foo bar foo bar, but in HTML there's Foo bar <br> foo bar, but adding an additional space in the "Then" line changed nothing

    – Michal
    Nov 21 '18 at 10:29











  • And btw, the first option (as described in my question) is 99% times - I think about focusing overcoming this <br> tag first, then think about the second issue, if needed

    – Michal
    Nov 21 '18 at 10:36






  • 1





    @Michal this looks more complicated , but shuold cover all 3 cases (including the one before question was modified): //h1[starts-with(., "Foo bar") and normalize-space(substring-after(., "Foo bar"))="foo bar"]. With this XPath we can ignore <br> as well as spaces between 1st and 2nd text

    – Andersson
    Nov 21 '18 at 10:39


















1














Instead of evaluating child text node (text()) you can evaluate string representation of header:



//h1[normalize-space()='" + name + "']





share|improve this answer
























  • Following xpath doesn't work, but I'm looking in this way, thanks :)

    – Michal
    Nov 21 '18 at 10:11











  • @Michal It should work with the provided HTML sample... Can you update your HTML sample if your simplified code source doesn't look like the real one? Also check whether your name variable is actually "Foo bar foo bar", but not "Foo barfoo bar" or something else

    – Andersson
    Nov 21 '18 at 10:15













  • Added. I spotted that this is Foo bar foo bar, but in HTML there's Foo bar <br> foo bar, but adding an additional space in the "Then" line changed nothing

    – Michal
    Nov 21 '18 at 10:29











  • And btw, the first option (as described in my question) is 99% times - I think about focusing overcoming this <br> tag first, then think about the second issue, if needed

    – Michal
    Nov 21 '18 at 10:36






  • 1





    @Michal this looks more complicated , but shuold cover all 3 cases (including the one before question was modified): //h1[starts-with(., "Foo bar") and normalize-space(substring-after(., "Foo bar"))="foo bar"]. With this XPath we can ignore <br> as well as spaces between 1st and 2nd text

    – Andersson
    Nov 21 '18 at 10:39
















1












1








1







Instead of evaluating child text node (text()) you can evaluate string representation of header:



//h1[normalize-space()='" + name + "']





share|improve this answer













Instead of evaluating child text node (text()) you can evaluate string representation of header:



//h1[normalize-space()='" + name + "']






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 9:52









AnderssonAndersson

38.5k103266




38.5k103266













  • Following xpath doesn't work, but I'm looking in this way, thanks :)

    – Michal
    Nov 21 '18 at 10:11











  • @Michal It should work with the provided HTML sample... Can you update your HTML sample if your simplified code source doesn't look like the real one? Also check whether your name variable is actually "Foo bar foo bar", but not "Foo barfoo bar" or something else

    – Andersson
    Nov 21 '18 at 10:15













  • Added. I spotted that this is Foo bar foo bar, but in HTML there's Foo bar <br> foo bar, but adding an additional space in the "Then" line changed nothing

    – Michal
    Nov 21 '18 at 10:29











  • And btw, the first option (as described in my question) is 99% times - I think about focusing overcoming this <br> tag first, then think about the second issue, if needed

    – Michal
    Nov 21 '18 at 10:36






  • 1





    @Michal this looks more complicated , but shuold cover all 3 cases (including the one before question was modified): //h1[starts-with(., "Foo bar") and normalize-space(substring-after(., "Foo bar"))="foo bar"]. With this XPath we can ignore <br> as well as spaces between 1st and 2nd text

    – Andersson
    Nov 21 '18 at 10:39





















  • Following xpath doesn't work, but I'm looking in this way, thanks :)

    – Michal
    Nov 21 '18 at 10:11











  • @Michal It should work with the provided HTML sample... Can you update your HTML sample if your simplified code source doesn't look like the real one? Also check whether your name variable is actually "Foo bar foo bar", but not "Foo barfoo bar" or something else

    – Andersson
    Nov 21 '18 at 10:15













  • Added. I spotted that this is Foo bar foo bar, but in HTML there's Foo bar <br> foo bar, but adding an additional space in the "Then" line changed nothing

    – Michal
    Nov 21 '18 at 10:29











  • And btw, the first option (as described in my question) is 99% times - I think about focusing overcoming this <br> tag first, then think about the second issue, if needed

    – Michal
    Nov 21 '18 at 10:36






  • 1





    @Michal this looks more complicated , but shuold cover all 3 cases (including the one before question was modified): //h1[starts-with(., "Foo bar") and normalize-space(substring-after(., "Foo bar"))="foo bar"]. With this XPath we can ignore <br> as well as spaces between 1st and 2nd text

    – Andersson
    Nov 21 '18 at 10:39



















Following xpath doesn't work, but I'm looking in this way, thanks :)

– Michal
Nov 21 '18 at 10:11





Following xpath doesn't work, but I'm looking in this way, thanks :)

– Michal
Nov 21 '18 at 10:11













@Michal It should work with the provided HTML sample... Can you update your HTML sample if your simplified code source doesn't look like the real one? Also check whether your name variable is actually "Foo bar foo bar", but not "Foo barfoo bar" or something else

– Andersson
Nov 21 '18 at 10:15







@Michal It should work with the provided HTML sample... Can you update your HTML sample if your simplified code source doesn't look like the real one? Also check whether your name variable is actually "Foo bar foo bar", but not "Foo barfoo bar" or something else

– Andersson
Nov 21 '18 at 10:15















Added. I spotted that this is Foo bar foo bar, but in HTML there's Foo bar <br> foo bar, but adding an additional space in the "Then" line changed nothing

– Michal
Nov 21 '18 at 10:29





Added. I spotted that this is Foo bar foo bar, but in HTML there's Foo bar <br> foo bar, but adding an additional space in the "Then" line changed nothing

– Michal
Nov 21 '18 at 10:29













And btw, the first option (as described in my question) is 99% times - I think about focusing overcoming this <br> tag first, then think about the second issue, if needed

– Michal
Nov 21 '18 at 10:36





And btw, the first option (as described in my question) is 99% times - I think about focusing overcoming this <br> tag first, then think about the second issue, if needed

– Michal
Nov 21 '18 at 10:36




1




1





@Michal this looks more complicated , but shuold cover all 3 cases (including the one before question was modified): //h1[starts-with(., "Foo bar") and normalize-space(substring-after(., "Foo bar"))="foo bar"]. With this XPath we can ignore <br> as well as spaces between 1st and 2nd text

– Andersson
Nov 21 '18 at 10:39







@Michal this looks more complicated , but shuold cover all 3 cases (including the one before question was modified): //h1[starts-with(., "Foo bar") and normalize-space(substring-after(., "Foo bar"))="foo bar"]. With this XPath we can ignore <br> as well as spaces between 1st and 2nd text

– Andersson
Nov 21 '18 at 10:39




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53409191%2fhandling-br-tag-in-xpath-through-cucumber%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy