Toggle navigation
Home
(current)
Selenium Training
Course Details
Free Videos
Support Forum
QTP UFT Training
Course Details
Free Videos
Support Forum
Appium Training
Course Details
Free Videos
Support Forum
Contact Us
(current)
All Courses
(current)
Login
(current)
Avail Discount
Name
Email
Phone Number
Tools
Selenium
QTP/UFT
Appium
Enroll Now
Home
Forum
Selenium Forum
Loop not working while counting number of elements in
Loop not working while counting number of elements in
M
Posted on 12/12/2016
Hi ,
please check below code and let me know where i am wrong :
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
public class SecondClass {
public static WebDriver Driver=null;
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Rachit\\workspace\\Module11\\Browser_Drivers\\chromedriver.exe");
Driver = new ChromeDriver();
Driver.manage().window().maximize();
Driver.navigate().to("http://www.americangolf.co.uk/golf-clubs/fairway-woods");
List<WebElement> alllinks=Driver.findElements(By.xpath("//*[@id='secondary']/div[1]/div[3]"));
System.out.println(alllinks.size());
for (int i=0;i<alllinks.size();i++)
{
System.out.println("___________________________");
System.out.println(alllinks.get(i).getText());
String text=alllinks.get(i).getText();
System.out.println(getParenthesesContent1(alllinks.get(i).getText()));
/*String temp[]=text.trim().split("[a-zA-z]+");
int count=0;
System.out.println(temp.length);
int y;
for (y=0;y<temp.length;y++)
count+=Integer.parseInt(temp[y]);
System.out.println(count);*/
//alllinks.get(i).click();
System.out.println(Driver.getTitle());
//Driver.get("http://shopping.rediff.com/");
//alllinks=Driver.findElements(By.xpath("//*[@id='popular_cat']/h3/a"));
}
}
public static String getParenthesesContent1(String str){
return str.substring(str.indexOf('(')+1,str.indexOf(')'));
}
}
M
Replied on 13/12/2016
What is error