kkr
kkr

Reputation: 33

How to replace/remove comma from a tezt using Selenium+java?

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();

Upvotes: 0

Views: 2588

Answers (3)

syed naveed
syed naveed

Reputation: 95

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 );

Upvotes: -1

user3045844
user3045844

Reputation: 62

Just use String.replace

driver.findElement(By.xpath("//div[@id='mainContents']/div[2]/div/table/tbody/tr/td")).getText().replace(",", "")

Upvotes: 0

CosminO
CosminO

Reputation: 5226

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));

Upvotes: 0

Related Questions