Mathan
Mathan

Reputation: 302

XPath of French Characters

I have a HTML code

<a id="cmplobremoveTéléphonie+default" class="cmpLOB-remove-btn" onclick="cmpLobRemoveButtonHandler(event, this);" style="text-decoration:none;" href="javascript:void(0)">Retirer</a>

I need to click on the element with xpath as @id='cmplobremoveTéléphonie+default'.

In Cucumber, I have a feature file step as

When Click on remove Button and click on confirm "Téléphonie"

The corresponding method is,

@When("^Click on remove Button and click on confirm \"([^\"]*)\"")
    public void remove_Button(String remove) throws Throwable {
        String remove_Required = "cmplobremove" +remove +"+default";
        driver.baseDriver.findElement(By.id(remove_Required)).click();
        Thread.sleep(1000);
        driver.baseDriver.findElement(By.linkText("Confirm")).click();
        log.info(remove + "is removed");
    }

When I try to execute the above step, I'm getting the following NullPointerException,

org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"groupIcon+default+T?l?phonie"}

It seems the french text cannot be passed in a similar way to English Text as a string argument. As you can see that Téléphonie is mentioned as T?l?phonie. Seems something to do with UTF-8/UTF-16.

Solutions are appreciated on how to parse the value.

Upvotes: 0

Views: 850

Answers (2)

Mathan
Mathan

Reputation: 302

Seems the default file encoder is ANSI for windows. I have changed the encoder to UTF-8 and now it's working without any issues.

Upvotes: 1

Kushal Bhalaik
Kushal Bhalaik

Reputation: 3384

try altenative for identifying that element as below using:

 driver.baseDriver.findElement(By.xpath("//a[contains(.,'Retirer')]").click();
 Thread.sleep(1000);
 driver.baseDriver.findElement(By.linkText("Confirm")).click();

Upvotes: 0

Related Questions