I am facing problem to apply loop and tick all the check box under a page.
Kindly suggest me to tick all the check box in page. Please follow the below steps 1. Go to Url "http://kesdee.com/buyOnline.html" 2. Go to dropdown'Course Groups' and select "Bank Branch Management" 3. tick all the check box under 'View Less' link 4. click all the 'View More' links one by one and tick all the check box Working on selenium Web Driver using java. package com.kesdee.newShoppingCart; import java.util.ArrayList; import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.support.ui.Select; import org.testng.annotations.Test; public class CourseIterator { public String baseUrl = "http://kesdee.com/buyOnline.html"; public WebDriver driver ; //Actions action = new Actions(driver); @Test public void mpgiteration() throws Exception { driver = new FirefoxDriver(); driver.get(baseUrl); Thread.sleep(5000); Select select = new Select(driver.findElement(By.id("category2"))); List<WebElement> list = select.getOptions(); Object[] optList = list.toArray(); ArrayList listFromGUI=new ArrayList(); String[] optArr = new String[optList.length]; for(int i=0; i<optList.length; i++) { optArr[i] = ((WebElement) optList[i]).getText(); listFromGUI.add(optArr[i]); } int size= listFromGUI.size()-1; System.out.println("size of array :"+size); for(int j=0;j<=size;j++){ select.selectByIndex(0); Thread.sleep(5000); List<WebElement> productGroupCount = driver.findElements(By.className("ProGroupName_btn")); System.out.println("productGroup count is:"+productGroupCount.size()); List<WebElement> productCount = driver.findElements(By.className("addto_Cart")); System.out.println("Product count is:"+productCount.size()); //for(int k=0;k<productGroupCount.size();k++){ //driver.findElement(By.className("ProGroupName_btn")).click(); //driver.findElement(By.xpath("html/body/div[6]/div/div/div/div/div[3]/div[3]/div[1]/h6["+(k+1)+"]/button")).click(); //driver.findElement(By.xpath("html/body/div[6]/div/div/div/div/div[3]/div[3]/div[1]/h6["+(k+1)+"]/button")); Thread.sleep(3000); //for adding products for(int l=0;l<productCount.size();l++){ List<WebElement> courseCount = driver.findElements(By.className("checkbox")); System.out.println("Course count is:"+courseCount.size()); String textCheck = driver.findElement(By.className("_view_crse")).getText(); System.out.println("textCheck is: "+textCheck); if(l==0){ driver.findElement(By.xpath("html/body/div[6]/div/div/div/div/div[3]/div[3]/div[1]/ul/li["+(l+1)+"]/a[2]")).click(); driver.findElement(By.xpath("html/body/div[6]/div/div/div/div/div[3]/div[3]/div[1]/ul/li["+(l+1)+"]/a[2]")).click(); } else{ Thread.sleep(3000); driver.findElement(By.xpath("html/body/div[6]/div/div/div/div/div[3]/div[3]/div[1]/ul/li["+(l+1)+"]/a[2]")).click(); } //for adding course for(int n=0;n<5;n++){ //driver.findElement(By.className("checkbox")).click(); driver.findElement(By.xpath("html/body/div[6]/div/div/div/div/div[3]/div[3]/div[1]/ul/li["+(l+1)+"]/div["+(n+3)+"]/div[1]/input")).click(); Thread.sleep(10000); } } //} } } } |
Free forum by Nabble | Edit this page |