0
votes

My Webpage contains text like 'User,'. I need to capture this text without comma. When i am doing assertEquals between the user entered text(User) and text retrieved from the webpage(User,), it failed because of extra comma.Can you help how to replace or remove that comma and getText?

Using the below xpath, i am capturing the text, driver.findElement(By.xpath("//div[@id='mainContents']/div[2]/div/table/tbody/tr/td")).getText();

3

3 Answers

0
votes

Let's say you place your text in t and you only want to remove the last comma (if present)

    t=driver.findElement(By.xpath("//div[@id='mainContents']/div[2]/div/table/tbody/tr/td")).getText();
    if(t.charAt(t.length()-1).equals(","))
        t=t.substring(0,t.length()-2));
0
votes

Just use String.replace

driver.findElement(By.xpath("//div[@id='mainContents']/div[2]/div/table/tbody/tr/td")).getText().replace(",", "")
-1
votes
string usertext=driver.findElement(By.xpath("//div[@id='mainContents']/div[2]/div/table/tbody/tr/td")).getText();     
string actual = usertext.replace(",");  
Assert.equals(expected, actual );