Quantcast
Channel: Active questions tagged html - Stack Overflow
Viewing all articles
Browse latest Browse all 74735

C# Selenium Function to take user input and click on xpath text containing " "?

$
0
0

I am writing a function that is supposed to take in a string, and click on the html element containing text matching the string.

But in some cases, the element's text contains the special characters &nbsp, and my function fails to find the element.

I posted my current solution below which I found in another post, but this does not work either. I've also tried normalize-space, but that only works for space characters, and not &nbsp

        public static void ClickOnItem(string itemName)
        {
            IWebElement target = BrowserUtility.FindElement(By.XPath(String.Format("//div[translate(.,'\u00A0','')='{0}']",itemName)));
            TestUtility.ClickElement(target);
        }

The HTML element I am trying to click on looks like this:

<div>Foo&nbsp;Doo&nbsp;Item</div>

Ideally, the user would pass 'Foo Doo Item' into the function, and the function would click on the div element.

Any help on if this is possible would be greatly appreciated.


Viewing all articles
Browse latest Browse all 74735

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>