Need Help in Module 13 Exercises | Selenium Forum
M
Posted on 08/03/2016
Hi,

Need some help in solving module 13 Exercises(Cricket Match Problem)

I am trying this for two days but i am not getting result, it is going into infinite loop,

i was able to print the individual runs of player, but i was not able to add them with a new variable as explained in the below written code by me called all_runs.

I tried to debug the program but the control was going to some other class, not able to figure it out, please help me

can any one help me out on this

[b:5kljo228][u:5kljo228]Program:[/u:5kljo228][/b:5kljo228]

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Team_Score_Problem {

public static void main(String[] args) {

WebDriver dr = new FirefoxDriver();
dr.manage().window().maximize();
dr.get("http://www.espncricinfo.com/south-africa-v-australia-2015-16/engine/match/884347.html");
dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

for (int i=2;i<=22;i=i+2){
String S1 = "//*[@id='full-scorecard']/div[2]/div/table[1]/tbody/tr[";
String S2 = "]/td[4]"; [b:5kljo228][u:5kljo228]// xpath broken into two parts[/u:5kljo228][/b:5kljo228]


List <WebElement> player_runs = dr.findElements(By.xpath(S1+i+S2));[b:5kljo228][u:5kljo228]//the individual player runs are put into list.[/u:5kljo228][/b:5kljo228]


String runs = player_runs.get(0).getText();[b:5kljo228][u:5kljo228]// getting the individual player runs[/u:5kljo228][/b:5kljo228]

int ipr = Integer.parseInt(runs);[b:5kljo228][u:5kljo228]//converting the individual player runs to integer[/u:5kljo228][/b:5kljo228]
System.out.println(ipr);

int all_runs = 0; [b:5kljo228][u:5kljo228]// initiated a new variable all_runs = 0[/u:5kljo228][/b:5kljo228]

String total_score = dr.findElement(By.xpath("//*[@id='full-scorecard']/div[2]/div/table[1]/tbody/tr[25]/td[4]/b")).getText(); [b:5kljo228][u:5kljo228]// this is the total score found by xpath[/u:5kljo228][/b:5kljo228]

int tr = Integer.parseInt(total_score);[b:5kljo228][u:5kljo228]// coverted the total score to integer[/u:5kljo228][/b:5kljo228]

[b:5kljo228][u:5kljo228]//in this loop comparing with all_runs variable to converted value of total score[/u:5kljo228][/b:5kljo228]

while (all_runs <= tr){
all_runs = all_runs + ipr;
System.out.println(all_runs);
}
}

}

}

M
Replied on 09/03/2016

[code:1gulym0l] while (all_runs <= tr) {
all_runs = all_runs + ipr;
System.out.println(all_runs);
}[/code:1gulym0l]

what are you truing to do in this code snippet?


M
Replied on 09/03/2016

I am first initializing the all_runs variable to zero

then [b:3o164rxt][u:3o164rxt]tr is the variable holding converted value(from string to integer)[/u:3o164rxt][/b:3o164rxt] of the total score of the match

then i am comparing all_runs with the total score in while loop up to equal to tr value(total_score) and it is going in infinite loop


M
Replied on 09/03/2016

[color=#FF0000:1e3vcasj]all_runs/ipr[/color:1e3vcasj] has a value of 9 and [color=#FF0000:1e3vcasj]tr [/color:1e3vcasj]has value of 110 that is why its going into the infinite loop.

try to find different way to add them.