Getting the old value of a table element, how can I get the new value?

lee :

I am trying to scrape some data from the site whoscored.com. (https://www.whoscored.com/Regions/81/Tournaments/6/Seasons/7406/Stages/16428/PlayerStatistics/Germany-Bundesliga-II-2018-2019)

I click on the detailed tab and am sorting the players of the german second bundesliga by minutes. The problem is, that after clicking those tabs and what seems like succesfully getting the new table (first box of code)

celtext still gives me the value of the initial table, the one before clicking on the mins and detail tab. (second block of code)

How do I make sure I get the updated info when retrieving the celtext?

output wanted:

  1. first click detailed
  2. click mins
  3. first person should be Daniel Heurer Fernandes

output in reality:

  1. first click detailed (succesful)
  2. click mins (players get sorted by mins)
  3. get celtext (all info about Philipp Klement is shown.... :( )

Really appreciate all of your help!

tried solutions

Ive tried setting the Thread to sleep for 8 seconds after each click on the table, but it doesnt affect the result. I know it probably has to do with the elements not being loaded completely or the click not resulting in a "hard-click" which affects the data. However, the page does change to the table I want it to be in.

code

    WebElement detail = driver.findElement(By.xpath("//*[@id=\"detailed-statistics-tab\"]/a")); // selects detailed tab in stats
    ex.executeScript("arguments[0].click();", detail);

int ok_size1=driver.findElements(By.xpath("//*[@id=\"player-table-statistics-head\"]/tr/th[5]")).size(); // sorts by mins
    driver.findElements(By.xpath("//*[@id=\"player-table-statistics-head\"]/tr/th[5]")).get(ok_size1-1).click();


WebElement theTable = driver.findElement(By.xpath("//*[@id=\"player-table-statistics-body\"]"));

    List < WebElement > rows_table = theTable.findElements(By.tagName("tr"));
    rows_count = rows_table.size();
    for (int row = 0; row < rows_count; row++) {
        List < WebElement > Columns_row = rows_table.get(row).findElements(By.tagName("td"));
        int columns_count = Columns_row.size();
        for (int column = 0; column < columns_count; column++) {
            String celtext =  Columns_row.get(column).getAttribute("innerHTML");

Expect the output of Daniel Heur Fernandes but get Philipp Clement

Sureshmani :

The issue is finding elements with tag-name with in the table. Instead try the following solution to get the list of row elements with player links,

List<WebElement> players = driver.findElements(By.xpath("//*[@id='statistics-table-detailed']//tr//a[@class='player-link']"));
for(WebElement player:players)
{
System.out.println(player.getText());
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=163118&siteId=1