0

My question is similar to this one: How to get HTML code of a WebElement in Selenium

I am trying to hit a close button, that looks like this:

OuterHTML: <input class="form-control btn btn-clear" style="font-family: MapIcons; padding: 0px;" value="" type="button">

That value attribute appears in the Unicode Lookup as Hex 0xE01D

I am trying to match that attribute before I click on it.

This is my code:

List<WebElement> elements = driver.findElements(By.xpath("//input[contains(@class, 'form-control btn btn-clear')]"));
    Common.myPrint(thisClass + " elements count: " + elements.size());
    for (WebElement element : elements) {
        // select an element
        if(element.isDisplayed())   {
            String text=element.getAttribute("value");
            if(text!=null) {
                Common.myPrint(thisClass + " text: " + text);
                // I would like to put compare text here, to ensure I have
                // correct element, before clicking on it.
            }

        }
    }

I have run this, and the Console.log displays this:

text: ?

so it would appear that WebElement.getAttribute("value") does not return that value accurately anyway.

Steve Staple
  • 2,983
  • 9
  • 38
  • 73
  • 2
    It can't display it, doesn't mean it doesn't return it correctly. You need to make sure `Common.myPrint` is working correctly with UTF8. Also it should work if you select element like this: `driver.findElement(By.xpath("//input[contains(@value, '\\uE01D')]"));` – timbre timbre Apr 10 '18 at 21:57
  • 1
    `driver.findElement(By.cssSelector("input[value='\uE01D']"));` should return the element from the HTML of your post. Be aware that your console/output needs to support Unicode to property display the character. If it doesn't, the character is replaced with a `?`. – Florent B. Apr 10 '18 at 23:07

0 Answers0