title: Find element via "findElementsBy", check innerText, refresh page, download or loop
body: <p>I have a page where a process gets kicked off, and then the page needs to be refreshed until &quot;Status&quot; on a table goes to &quot;Processed&quot;, at which point a report can be downloaded.</p>
  <pre><code>...
                String processing=&quot;NotFinished&quot;;
                WebElement table = driver.findElement(By.id(&quot;TableID&quot;)); 
                List&lt;WebElement&gt; allRows = table.findElements(By.tagName(&quot;tr&quot;)); 
                while(processing.equals(&quot;NotFinished&quot;)) {
                for (WebElement row : allRows) {
                      List&lt;WebElement&gt; cells = row.findElements(By.tagName(&quot;td&quot;)); 
                      for (WebElement cell : cells) {
                          if(cell.getText().equals(&quot;ReportName&quot;)) {
                              String[] ColData = row.getText().split(&quot; &quot;);                    
                      if(ColData[5].equals(&quot;Processed&quot;)) {
                          //click download
                          wait.until(ExpectedConditions.elementToBeClickable(By.id(&quot;DownloadButtonID&quot;)));
                      Thread.sleep(250);
                      driver.findElement(By.id(&quot;DownloadButtonID&quot;)).click();
                          processing = &quot;Finished&quot;;
                          System.out.println(&quot;DownloadClicked&quot;);
                      } else {
                              System.out.println(&quot;Refreshing&quot;);
                              wait.until(ExpectedConditions.elementToBeClickable(By.id(&quot;RefreshButtonID&quot;)));
                              Thread.sleep(250);
                              driver.findElement(By.id(&quot;RefreshButtonID&quot;)).click();
                              Thread.sleep(5000);       
                          }
                      }
                  }    
              }
  ...
  </code></pre>
  <p>At this point I have been able to confirm that &quot;ColData[5]&quot; is pulling in the correct value. I have been trying to move the &quot;while&quot; statement to different areas in this chunk of code to see if I can get it to work, but I am seeing 2 main behaviors.</p>
  <p>If I locate the where below the second for, then it will simply loop forever. The value for &quot;ColData[5]&quot; is getting updated on the page, but Java isn't seeing that.</p>
  <p>When I locate the where like it is here, it will loop a few times between the for statements and then will seemingly spontaneously pop out of the while statement without hitting the &quot;processing = &quot;Finished&quot;;&quot; statement.</p>
  <p>I was thinking that I may need to break out of the for statements so that Java correctly backs up to redefining the table at the start of the loop after clicking the refresh button, but doing a break seemed to make it skip all of the above.</p>
  <p>Can anyone point me in the direction of getting this code to: Get the table data, get the value of the cell a few columns over from the Report Name I am targeting, determine if it says &quot;Processed&quot;, If yes, click download and move on. If no, wait 5 seconds, click refresh, and check again.</p>
  <p>I know this is pretty ungodly bad code, but at this point the name of the game is anything that works, and in the future I can work on being better at the language.</p>