Home > Enterprise >  Table not loading in chromedriver while creating selenium test cases using eclipse IDE
Table not loading in chromedriver while creating selenium test cases using eclipse IDE

Time:10-10

I am fetching the data from a table using selenium chromedriver. When I am opening the webpage normally using my chrome browser, the table is loading correctly. But during execution with selenium, the webpage is loaded but table is not loading. I also removed the implicit wait and just navigated to the webpage to see if the table is loaded or not but still after 10 mins table is not loading, but it loads pretty fine and instantly in chrome browser.

  • Here is my code:-

    package automation;
    import java.time.Duration;
    import java.util.List;
    
    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.WebElement;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    
    public class table_handling {
    
       public static void main(String[] args) {
            // TODO Auto-generated method stub
               System.setProperty("webdriver.chrome.driver",".\\lib\\chromedriver.exe");
               WebDriver driver= new ChromeDriver();
               driver.manage().window().maximize();
               driver.get("https://www.nseindia.com/market-data/top-gainers-loosers");
               WebDriverWait wait=new WebDriverWait(driver,Duration.ofSeconds(20));
               wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='topgainer-Table']/tbody/tr/td[1]")));
               List<WebElement> obj=driver.findElements(By.xpath("//*[@id='topgainer-Table']/tbody/tr/td[1]"));
               WebElement temp;
               for(int i=0;i<obj.size();i  )
               {
                  temp=obj.get(i);
                  System.out.println(temp.getText());
    
               }
      }
    
     }
    

For your reference, I am attaching 2 screenshots, one of the normal page which loads pretty fine on chrome browser and 1 of the chromedriver in which table is is loading phase everytime. Normal chrome Browser Selenium chromedriver

CodePudding user response:

Use the presenceOfElementLocated instead of visibilityOfElementLocated and try it:

WebDriverWait wait=new WebDriverWait(driver,Duration.ofSeconds(20)); wait.until(ExpectedConditions.presenceOfElementLocated((By.xpath("//*[@id='topgainer-Table']"))));

CodePudding user response:

there is a similar question for the website in case at the following link --> Website Loading Only once then access denied - Selenium Webdriver

Probably the anti-bot protection has something to do with it.

  • Related