Reputation: 33
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
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
Reputation: 62
Just use String.replace
driver.findElement(By.xpath("//div[@id='mainContents']/div[2]/div/table/tbody/tr/td")).getText().replace(",", "")
Upvotes: 0
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