1

The betIn site i'm trying to extract data from is betIn.I have navigated to the section that includes a list of all teams that will currently be playing on the current day and i'm trying to extract the information about the teams but i'm currently only able to obtain 13 teams instead of all the teams.At first i thought storing the values in an Array was the problem hence i opted to move to an ArrayList but still bore the same problem Below is my code:

public class test {

public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver", "/Users/user/Desktop/chromedriver");

    WebDriver driver = new ChromeDriver();driver.navigate().to("https://sports.betin.co.ke/mobile#/dailyBundle/soccer/1-1000");
    List<WebElement> rows = driver.findElements(By.cssSelector(".match-content.table-a.soccer"));
    java.util.Iterator<WebElement> row_list = rows.iterator();
    ArrayList<String> teams = new ArrayList<>();
    ArrayList<String> bets = new ArrayList<>();
    while(row_list.hasNext()){
        WebElement rowItem = row_list.next();
        String unnecessary = rowItem.findElement(By.cssSelector(".match-content__row--info")).getText();
        String Content = rowItem.findElement(By.cssSelector(".match-content__info")).getText();
        String relevantContent = Content.replace(unnecessary,"");
        String bet = rowItem.findElement(By.cssSelector(".bets")).getText();
        teams.add(relevantContent);
        bets.add(bet);
    }
    System.out.println("These are the teams \n"+ teams);

    System.out.println("The size of teams is "+ teams.size());

    System.out.println("These are the odds \n"+ bets);
    driver.close();

}

}

Bradley Juma
  • 131
  • 13

1 Answers1

1

Did you notice that rows.size() is appearing zero always.

It is because page is not loaded completely but your code is getting executed.

If I run your code by applying some wait it works perfectly fine. I am able to get all teams.

Thread.sleep(10000) // wait for 10 seconds
List<WebElement> rows = testDriver.findElements(By.cssSelector(".match-content.table-a.soccer")); 

Using sleep in between your code is not wise thing to do. So, to make sure your page is loaded completely check this out Selenium - How to wait until page is completely loaded

paul
  • 4,333
  • 16
  • 71
  • 144