Lets take a webpage having multiple check boxes. How do I get the count of all checkboxes and how do I select them
1.Go to the following link and you will find checkboxes under Search Language. Below Code Snippet instructs selenium to get the check box count and select all the checkboxes one by onehttp://www.google.co.in/preferences?hl=en
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.openqa.selenium.server.SeleniumServer;
import com.thoughtworks.selenium.DefaultSelenium;
import com.thoughtworks.selenium.Selenium;
public class AjaxTests {
static SeleniumServer server;
static Selenium selenium;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
server = new SeleniumServer();
server.start();
selenium = new DefaultSelenium("localhost", 4444, "*iexploreproxy",
"http://www.google.com");
selenium.start();
selenium.open("/preferences?hl=en");
selenium.windowMaximize();
}
@AfterClass
public static void tearDownAfterClass() throws Exception {
selenium.close();
selenium.stop();
server.stop();
}
@Test
public void testAllCheckBoxes(){
//Get the count of all available check boxes
int checkBoxCount = selenium.getXpathCount("//form[@name='langform']/table[5]/tbody/tr[2]/td[3]
/table/tbody/tr/td/font[1]/label/input").intValue();
//Print the Check box count
System.out.println("Total Number of Check box count is : " + checkBoxCount );
int count = selenium.getXpathCount("//form[@name='langform']/table[5]/tbody/tr[2]/td[3]/table/tbody
/tr/td[1]/font[1]/label").intValue();
System.out.println(count);
for (int i = 1; i <=4; i++) {
for (int j = 1; j <= count; j++) {
if(i == 4 && j == 11){
break;
}
selenium.check("//form[@name='langform']/table[5]/tbody/tr[2]/td[3]/table/tbody/tr/td[" + i +
"]/font[1]/label"+"[" + j +"]/input");
}
}
}
}
Hi Sir ,
ReplyDeleteUr blog is really help .. i have a doubt in counting the checkbox ...
Wat does the Xpath //form[@name='langform']/table[5]/tbody/tr[2]/td[3]
/table/tbody/tr/td/font[1]/label/input").intValue();
stand for in the wensite ???
hi ,
ReplyDeletethis is gousia,I am trying to learning selenium on my own,but at some point i am struck,please help me out if there is any helpful material or you can provide guidance....
Let me know
right now I have a scenario,
ReplyDeletethat is
there is a checkbox with label "show only my items"when we check the check box,it should show the widgets created by the current user.
if we uncheck it should show all the other user widgets also
I was trying by Xpath ,i am not getting ,
please help me out
Hi your blog is very good.I have one doubt is it possible to apply automated testing using java selenium for a wordpress page having images graphs,pie charts?
ReplyDeletePlease reply soon if possible post some related example
thank you
Yes, You should be able to automate word press
Delete