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 | | |
[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"">
<html xmlns="" xml:lang="en" lang="en">
	<meta content="text/html; charset=UTF-8" http-equiv="content-type" />
	<title>UI5 Demo</title>
<table cellpadding="1" cellspacing="1" border="1">
<tr><td rowspan="1" colspan="3">Shopping Cart</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>

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.




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.