[Webdriver] take a substring,convert to Int , Then Assert data against DB!!!

1,480 views
Skip to first unread message

Rashmi

unread,
Oct 11, 2012, 1:33:21 AM10/11/12
to webd...@googlegroups.com
Hi,

I have this  "Displaying 1- 20 of 50"  on UI.
Now I have to take this "50" and validate against database total count.

I assume we have to locate element (<div id="tbtext-1380" class="x-toolbar-text x-box-item x-toolbar-item x-toolbar-text-default" role="presentation" style="margin: 0px; left: 1313px; top: 13px; " tabindex="-1">Displaying 1 - 20 of 50</div>),
Then find substring of "50" ,convert into int and then Assert.

I tried a lot but couldn't figure out..
Could anybody please help me regarding this,If this is the correct approach,If yes how to go about it.Or is there any other way...

Thanks in advance
Rashmi


Amit Agarwal

unread,
Oct 11, 2012, 5:24:29 AM10/11/12
to webd...@googlegroups.com
Rashmi, 

I am not sure what is the issue, but I am able to get my results with following code

Target Text Line on Result Page    782 items found

               WebElement searchResultCount = driver.findElement(....).gettext();
                int indexOfBlank = WebElement.getText().indexOf(" ");
String totalResultString = WebElement.getText().substring(0, indexOfBlank);
totalResult = Integer.parseInt(totalResultString);
return totalResult;

And then simple assert,

Regards,
Amit






Rashmi


--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/2ldlxff5U2kJ.
To post to this group, send email to webd...@googlegroups.com.
To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.

Rashmi

unread,
Oct 11, 2012, 10:48:31 AM10/11/12
to webd...@googlegroups.com
Thanks for the Reply Amit,Shall try this and update here.

Mark Collin

unread,
Oct 12, 2012, 1:30:36 AM10/12/12
to webd...@googlegroups.com

This is basic Java, nothing to do with Selenium, off the top of my head the answer is something like this:

 

//Take the original string

String sentence = "Displaying 1- 20 of 50"

//Split it into an array based upon whitespace

String[] words = sentence.split(" ")

//Get the last element in the array (this should be 50).

String result = words[words.length - 1]

 

The reason for using length -1 is that the first element in an array is 0 not 1.

Dibyaranjan Kar

unread,
Oct 12, 2012, 12:13:06 PM10/12/12
to webd...@googlegroups.com
Hi Rashmi,

Just adding from where Mark left-:

Interget.parseInt(String) // To parse the string to Interger now . You can assert this.

Thanks
Dibya

Rashmi

unread,
Oct 12, 2012, 8:18:01 PM10/12/12
to webd...@googlegroups.com

Thanks All  for the replies...Implemented the code  and its working fine ...

- Rashmi

Reply all
Reply to author
Forward
Message has been deleted
0 new messages