0
votes

This is the snapshot of Login popup : enter image description here

I'm newbie in Selenium webdriver. I wrote this code to figure out navigate commands but once the browser opens, there is a login popup that is displayed. I tried to close it using classname or xpath but timeout exception occurs.

Do I need to use explicit wait in this case? Could you help me to figure out what the problem is?

public class TestNavigateCommands {
WebDriver driver;
public void invokeBrowser(){
    try {
        System.setProperty("webdriver.chrome.driver", "/Users/himaja/Documents/chromedriver");
        ChromeOptions options=new ChromeOptions();
        options.addArguments("start-fullscreen");
        driver=new ChromeDriver(options);
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(40, TimeUnit.SECONDS);
        navigateCommands();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
public void navigateCommands(){
    try {
        driver.navigate().to("https://www.flipkart.com/");
        Thread.sleep(4000);
        driver.findElement(By.className("2AkmmA _29YdH8")).click();
        //driver.findElement(By.xpath("//*[@class='_2AkmmA _29YdH8']")).click();
        driver.findElement(By.xpath("//span[starts-with(text(),'Applicances')]")).click();
        driver.findElement(By.xpath("//span[contains(text(),'Microwave Ovens')]")).click();
        Thread.sleep(2000);
        driver.navigate().back();
        Thread.sleep(2000);
        driver.navigate().forward();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }



}


public static void main(String[] args) {
    TestNavigateCommands test1= new TestNavigateCommands();
    test1.invokeBrowser();

}

}

Exception :

[43.366][SEVERE]: Timed out receiving message from renderer: 37.150 [43.373][SEVERE]: Timed out receiving message from renderer: -0.007 org.openqa.selenium.TimeoutException: timeout

2
Hi Himaja :) What do you mean by "didn't work"? Does nothing happen? Do you get an exception? Does a gif of a dog pop up on the screen and laugh at you? - mrfreester
There is timeout exception that I'm getting. The popup is not closed and the other functions are not getting executed. - Himaja
can you add the timeout exception to your question? That likely has some valuable debugging information in it. - mrfreester
@Himaja, Please update your chromedriver version and try again - NarendraR
Can you update the Question with the full error stack trace and the line at which you see the exception? - DebanjanB

2 Answers

0
votes

Try this code it may help:

public class TestNavigateCommands {
     public static void main(String[] args) throws InterruptedException {
            try {                
                  System.setProperty("webdriver.chrome.driver", "/Users/himaja/Documents/chromedriver");
                  WebDriver driver = new ChromeDriver();
                  driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
                  WebDriverWait wait=new WebDriverWait(driver,50 );

                  driver.manage().window().maximize();

                  driver.navigate().to("https://www.flipkart.com/");          
                  driver.findElement(By.xpath("//button[contains(@class,'YdH8')]")).click();   


                  wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//a[@title='Appliances']//span"))));
                  driver.findElement(By.xpath("//a[@title='Appliances']//span")).click();         

            } catch (Exception e) {
                e.printStackTrace();
            }           
        }   
    }
0
votes
public class TestNavigateCommands {
WebDriver driver;

public void invokeBrowser() {
    try {
        System.setProperty("webdriver.chrome.driver", "/Users/himaja/Documents/chromedriver");
        ChromeOptions options = new ChromeOptions();
        options.addArguments("start-fullscreen");
        driver = new ChromeDriver(options);
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.manage().timeouts().pageLoadTimeout(60, TimeUnit.SECONDS);
        navigateCommands();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public void navigateCommands() {
    try {
        driver.navigate().to("https://www.flipkart.com/");          
        driver.findElement(By.xpath("//div[@class='_3Njdz7']//button[@class='_2AkmmA _29YdH8']")).click();
        WebDriverWait wait = new WebDriverWait(driver, 30);
        wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath("//a[@title='Appliances']//span"))));
        driver.findElement(By.xpath("//a[@title='Appliances']//span")).click();         
        Thread.sleep(2000);
        driver.navigate().back();
        driver.navigate().forward();
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}