Hope you're all well. I'm quite new to selenium and a complete newbie to stack overflowso i hope i'm not disobeying any rules here.
I am trying to create a test framework and some tests using the following
c#, selenium webdriver, specflow, nunit
I am currently running a query against a sql server DB to retrieve some text and then trying to use that text to verify and search for that element on the site. The problem i have is that the site has the element html encoded
For example:
Data retrieved from the database could be something like - "Alumina MB China metallurgical grade delivered...."
The element on the site is as follows -
<span class="com">Alumina MB China metallurgical grade delivered duty paid RBM/tonne</span>
Does anyone know how i could parse the data retrieved from the DB into the findElement command to easily find this element on the site whilst it contains
Look forward to hearing from you.
Many Thanks Suban
you should first replace all instances of
$nbsp;
in your xpath string toand then search for that
Explanation: Use xpath to find a
span
element with class containing the stringcom
, get the text from that (.
) replace all of the 
characters (i.e. unicode\u00A0
) with a regularspace
character, and strip leading and trailing whitespace (this last part may not be needed in your situation).Note: the string that should go in the single quotes after the
=
should only contain regular spaces.Try to escape html characters by using System.Web.HttpUtility.HtmlDecode
it works for me: