0

The below function is what I have been using to check texts on web pages, but the function fails to find text put under 'br' tag. Kindly advice.

C#:

 public static IWebElement CheckTextOnPage(IWebDriver driver, string _text)
    {
        var buildXpath = "//*[contains(translate(text()[normalize-space()],'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '" + _text.ToLower() + "' )]";
        return driver.FindElement(By.XPath(buildXpath));
    }

Sample Html:

<html>
<div>
Test string 1.
<br>Test string 2.
<br>Test string 3.
</div>
</html>
5
  • Could you post Relevant HTML? Commented Apr 15, 2020 at 14:43
  • _text.ToLower() what value this is ? if your value is Test string 2. this won't work? Commented Apr 15, 2020 at 14:55
  • XPath problem ? As @KunduK stated, please provide html code. You can try this alternate XPath expression : //text()[normalize-space()][contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '" + _text.ToLower() + "' )]/parent::* Commented Apr 15, 2020 at 15:04
  • @E.Wiest - Yeah! this is what I tried and worked. Commented Apr 15, 2020 at 15:09
  • Nice. If everything's fine, you can mark the answer as accepted. Commented Apr 15, 2020 at 16:41

1 Answer 1

1

You can try this alternate XPath expression :

//text()[normalize-space()][contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'), '" + _text.ToLower() + "' )]/parent::*
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.