<p class="details-info-block__text"><span class="details-info-block__label">Business Address 1:</span> 1010 Priority Way West Dr</p>
I want to verify the address value (e.g. "1010 Priority Way West Dr"). But retrieving it using XPath //span[contains(text(), 'Business Address 1')]/..
returns the following string
Business Address 1: 1010 Priority Way West Dr
-
Possible duplicate of How do I get particular textNode value of a DOM with SeleniumAlexey R.– Alexey R.2019年10月08日 13:56:33 +00:00Commented Oct 8, 2019 at 13:56
-
you are using //span where the text in the span is 'Business Address 1' if you used //p you could try and get the text from thatDEnumber50– DEnumber502019年10月08日 16:41:26 +00:00Commented Oct 8, 2019 at 16:41
2 Answers 2
- You get a string, and you know what that string should end with.
- There is https://docs.microsoft.com/en-us/dotnet/api/system.string.endswith?view=netframework-4.8
- You can use that, it's probably enough.
- If you know the allowed variations of Business Address 1: then you can remove those from the string.
- Maybe you know that your answer should always be after the first semi colon
You can retrieve all inner text of <p class="details-info-block__text">
and then parse out the required text using String-related toolset of C#. It will be quite a tricky thing to extract what you want using selenium since the latter piece of text is a separate "naked" text node in a DOM and Selenium cannot parse it to a dedicated WebElement
(anything having no associated tag)
Explore related questions
See similar questions with these tags.