Question: How to use XPath with Contains Text

Hello alltogether,

a tiny question, how to use XPath with contains text?

I tried for my SAP UI5 test

//span[contains(text(),'Shopping Card')]

but it doesn’t work.

Here my log

[info] Playing test case UI5 Demo / Shopping Cart
[info] Time: Fri Jul 20 2018 09:10:35 GMT+0200 (Mitteleuropäische Sommerzeit) Timestamp: 1532070635456
[info] OS: Windows Version: 10
[info] Browser: Chrome Version: 67.0
[info] If the test cannot start, please refresh the active browser tab
[info] Executing: | open | https://sapui5.hana.ondemand.com/demoapps.html | |
[info] Wait for the new page to be fully loaded
[info] Executing: | waitForPageToLoad | | |
[info] Executing: | select | //span[contains(text(),'Shopping Card')] | |
[info] Wait until the element is found
[error] Implicit Wait timed out after 10000ms
[error] Element //span[contains(text(),'Shopping Card')] not found
[info] Time: Fri Jul 20 2018 09:10:46 GMT+0200 (Mitteleuropäische Sommerzeit) Timestamp: 1532070646726
[info] Test case failed

I tried different commands but all without success.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
	<title>UI5 Demo</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Shopping Cart</td></tr>
</thead>
<tbody>
<tr><td>open</td><td>https://sapui5.hana.ondemand.com/demoapps.html<datalist><option>https://sapui5.hana.ondemand.com/demoapps.html</option></datalist></td><td></td>
</tr>
<tr><td>waitForPageToLoad</td><td><datalist><option></option></datalist></td><td></td>
</tr>
<tr><td>select</td><td>//span[contains(text(),'Shopping Card')]<datalist><option>//span[contains(text(),'Shopping Card')]</option><option>xpath=//span[contains(text(),'Shopping Card')]</option><option>xpath=(//span[contains(text(),'Shopping Card')])</option></datalist></td><td></td>
</tr>
</tbody></table>
</body>
</html>

So I tried the same in PowerShell with Selenium and here it works without any problems (line 109).

What is my error? Why can’t I find this element?

Thanks for tips and hints.

Cheers
Stefan

UI5DemoKatalon.JPG

UI5DemoKatalonPS.JPG

1. why do you using command to select options from list?
2. there is no Shopping Card on page … just Shopping Cart

1 Like

Hello Andrej,
thank you very much :slight_smile:
Sure, Card != Cart
Now it works. Sometimes I do not see the whole forest because of so many trees.
Thanks again.
Cheers
Stefan