Meghasri
Meghasri

Reputation: 105

Fetching SubString from the String in Selenium Webdriver

I have a Website where the userID differs for every login, Say for example When i login with userID 'Username1' this contains 0 to 8 characters, similarly if i login with userID 'Username123' contains 0 to 10 characters

I need to automate in such a way, that for every login system stores the user ID in a variable as follows

String FullUsername=driver.findElement(MyTeamInboxPage.username).getText();

My result for the userID 'Username1' would be Username1

I am gonna take substring from 4 to till end as follows

String actual=Fullactual.substring(4, 8);

But the sub string code will not work for every userID. How can i change my SubString code end character alone in such a way, it should work for every User ID

Upvotes: 0

Views: 10362

Answers (1)

Shahid
Shahid

Reputation: 2330

You can try:

String actual=Fullactual.substring(4, Fullactual.length());

Note: the endIndex of substring is exclusive. That means if you want to take a substring upto index 8, endIndex has to be 9. That's why I used Fullactual.length(), not Fullactual.length()-1

Upvotes: 1

Related Questions