Hi Guys ...here is a place where you can learn basic selenium like css locators and xpath locators and selenium RC using Java...
Sunday, January 30, 2011
Example for using GetEval in selenium to get the list of checkbox ids...
import com.thoughtworks.selenium.DefaultSelenium;
public class CheckBoxesStatusTest {
public static void main(String[] args) {
DefaultSelenium selenium = new DefaultSelenium("localhost", 8888,
"iexplore", "http://browsershots.org/");
selenium.start();
selenium.open("http://browsershots.org/");
selenium.waitForPageToLoad("30000");
String checkBoxIds = selenium.getEval("function getCheckBoxsStatus()
{"
+ "var cbgChkRefid='checked:';"
+ "var chkCounter=0;"
+ "var cbgNonChkRefid='unchecked:';"
+ "var unchkCounter=0;"
+ "var docref = window.document;"
+ "var ipRef=docref.getElementById('startform').getElementsByTagName('input');"
+ "for(var k=0;k< ipRef.length;k++){
+"
if (ipRef[k].type == 'checkbox') {
+"
if (ipRef[k].checked) {
+"
chkCounter = chkCounter + 1;
"
+"
cbgChkRefid = cbgChkRefid + ' ' + ipRef[k].id;
+ "
}
+"
else {
"
+"
unchkCounter = unchkCounter + 1;
" +"
cbgNonChkRefid = cbgNonChkRefid + ' ' + ipRef[k].id;
"+"
}
"+"
}
"+"
}
"+"
return (cbgChkRefid + ' cheked Checkboxes
Number' + chkCounter.toString() + '::' + cbgNonChkRefid + ' uncheked
Checkboxes Number' + unchkCounter.toString() + '
totalNumberofcheckboxesonthePage:' + ipRef.length);
"+"
}
"+"
getCheckBoxsStatus();
");
checkBoxIds = checkBoxIds.replaceAll(": ", "\n ");
System.out.println("All checked and Unchecked IDS: \n"+checkBoxIds.replaceAll(": ", "\n "));
System.out.println("All checked and Unchecked IDS in line by lineformat: \n "+checkBoxIds.replaceAll("", "\n "));
}
}
Subscribe to:
Post Comments (Atom)
It appears the for loop is incomplete in the above.
ReplyDeleteRegards,
Greg
hi greg,
ReplyDeleteThanks for your suggestion.
I uploaded twice in the post.
It looks like the blogger post itself is truncating that part . I dont know the reason.
Please send me an email id at the following address . I will send you the file in an email . which is ready to execute. Thanks for finding the mistake. meerasaab786@gmail.com
HI greg You can find the similar thread replied by me at this URL.
ReplyDeletehttp://groups.google.com/group/selenium-users/browse_thread/thread/ba584f2dc1c10024/0ac08256a1097fad?lnk=gst&q=nagaraju+dasam#0ac08256a1097fad
Hi Meerasaaheb,
ReplyDeleteCould you try to find and change the background theme so that the widget/content space is wider to accommodate more text without having to scroll a longer bar?
It is posing severe readability inconvenience to follow your above example!
Thanks,
McKiran.
I am sorry my friend.. I was not active in this since long time... Any how because of your comment i took my some time today and made some change atleast others might benefit.. cheers :-)
Delete