Element not found (non-breaking space?)

Hi, I am encountering an error within a test case, where an element cannot be found. Below is a snippet of the code, where I am attempting to verify the element text for the paragraph starting “Tickets and travelcards”:

Choose your ticket or travelcard

Please note:

Tickets and travelcards will be available to use the day after you buy them but you can purchase them up to 7 days in advance. You can only purchase one ticket at a time, and you must collect this from a smart reader before further online purchases are possible.

Product terms and conditions apply, for more information please check here. Some tickets and travelcards are restricted by card type.

Given that other “verify element text” steps work fine, I wonder whether it is the non-breaking space that is present after “travelcards”, which shows as “&nbsp” when I inspect the code in Chrome. The website itself is developed by a supplier, so I cannot simply edit the source code to confirm this.

Below are the object properties that I am using to detect the element:

tag equals p (detect object)
text equals Tickets and travelcards will be available to use the day after you buy them but you can purchase them up to 7 days in advance. You can only purchase one ticket at a time, and you must collect this from a smart reader before further online purchases are possible.
(detect object)
xpath equals id(“center”)/div[@class=“groupBlockA blockAFull”]/div[@class=“lifted basket-page”]/span[@class=“spaceRemainingOnCard”]

Below is the error displayed within the console:

[FAILED] - Test Cases/Purchase Metrolink Single Adult FAILED because (of) Verify element text of test object ‘Object Repository/GMT Portal - Production/Page_Select a ticket or travelcard/p_Tickets and travelcards will’ FAILED. (Root cause: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/GMT Portal - Production/Page_Select a ticket or travelcard/p_Tickets and travelcards will’ located by 'By.xpath: //p[(text() = 'Tickets and travelcards will be available to use the day after you buy them but you can purchase them up to 7 days in advance. You can only purchase one ticket at a time, and you must collect this from a smart reader before further online purchases are possible.

’ or . = 'Tickets and travelcards will be available to use the day after you buy them but you can purchase them up to 7 days in advance. You can only purchase one ticket at a time, and you must collect this from a smart reader before further online purchases are possible.

‘)]’ not found)

Can anyone help me with this?

Hi Daniel,

Firstly, I’m not an “xpath guy” – I’m much more attuned to css. That said, the xpath you supplied doesn’t seem to match the HTML you supplied.

id("center")/div[@class="groupBlockA blockAFull"]/div[@class="lifted basket-page"]/span[@class="spaceRemainingOnCard"]

A quick skim reveals:

1 - a span in the xpath that does not exist in the HTML
2 - a class basket-page that does not exist in the HTML

Regardless of the nbsp issue, (and btw, it looks more like a rendering of   to my eyes) if the xpath is wrong, it’s a non-starter. If it were me, I’d recode it to use css selectors.

If I’ve missed something obvious (to an xpath guy) I apologize :wink:

HTH
Russ

Russ, thanks for the response. I have noticed that I added the incorrect xpath (I am seeing a similar issue on a later test case which uses the same text), below is the correct xpath:

id(“center”)/div[@class=“groupBlockA blockAFull”]/div[@class=“lifted select-product-page”]/p[2]

As mentioned above, unfortunately it’s not my development, so unfortunately cannot recode it (or not request it be altered in a timely manner).

Given the the revised xpath, do you have any thoughts on why the element is not being found, or suggestions on what may work to defect it?

Hi Daniel

Yes, I think that xpath looks good now. As for recoding… I meant the test strategy be changed to css, not that you change the html.

But to help further, I think I’d need to see the actual page – is it public?

Other than that, you might get more mileage by digesting this:

HTH
Russ

p.s. if that SO link provides an answer, please post back here so we all get the benefit! Thanks.

Thanks for the further feedback, I did stumble across the SO page a few days ago; however adding ${nbsp} in between “travelcards” and “will” still did not result in the element being found.

I will read up on your suggestion of using CSS. I only have a little knowledge of it; however if it helps get my test case working then it will be worth the effort!

Lastly, the webpage is public, albeit appears after logging in as a registered customer.

If that’s a faithful copy of the HTML and text that you pasted into your original post, then be aware that you should try both "  " and "  ". Laboring the point, that’s

"&nbsp;<space>"

and

"<space>&nbsp;"

It’s impossible to see which combination you have just from reading it.

Guessing you’ll be kicking yourself if that turns out to be the solution :slight_smile:

@Russ Thomas To let you know (after a considerable delay!) that I migrated my test scripts to use CSS as the selection method and this resolved the issue. Thanks for your suggestion.