[quote:1r6ial0d]1. In module 13 there are some exercise which we have to practice in which i am facing an problem, can you tell me how can i get the sum of all the link text displayed in the brand menu.[/quote:1r6ial0d]
try some thing like this
List<webelement> links=driver.findelements(By.tagname("a"));
[quote:1r6ial0d]2. I had tried to get each and every text from those link, but how can i add those text and compare them with total product in fairway woods.[/quote:1r6ial0d]
could you explain again what is the problem.
here is the piece of my code, there is an error "Exception in thread "main" java.lang.NumberFormatException: For input string: "(12)". The fetched text from the link contains (12) how to separate those brackets and just use the no.
code
[color=#FF0000:291mdv05] WebDriver Findsum= new HtmlUnitDriver();
Findsum.manage().window().maximize();
Findsum.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
Findsum.get("http://www.americangolf.co.uk/golf-clubs/fairway-woods");
List<WebElement> box = Findsum.findElements(By.xpath("//*[@id='secondary']/div[1]/div[3]/div/ul/li"));
System.out.println(box.size());
String link1="//*[@id='secondary']/div[1]/div[3]/div/ul/li[";
String link2="]/a/span[2]";
int sum =0;
for(int j =0; j<box.size(); j++)
{
List<WebElement> linksno = Findsum.findElements(By.xpath(link1+j+link2));
linksno.size();
for(int i = 0; i<linksno.size(); i++)
{
String text = linksno.get(i).getText();
int no = Integer.parseInt(text);
sum = sum + no;
}
}
System.out.println(sum);
String totaltext = Findsum.findElement(By.xpath("//*[@id='primary']/div[2]/div[1]/div[1]/span")).getText();
int totalno = Integer.parseInt(totaltext);
if(totalno == sum)
{
System.out.println("The brand list item are equal to total item");
}
else
{
System.out.println("Error");
}
}[/color:291mdv05]
you have to use substring function.
http://stackoverflow.com/questions/4503656/in-java-removing-first-character-of-a-string