0

i am learning Selenium with java . My use case is :

  1. Browse www.Google.com
  2. Search for "Gmail Login"
  3. open first link
  4. click on signin button (it will take me to login page)
  5. Enter email , click next then enter password
  6. click next

There are two scenarios ,one when i directly browse for gmail login page and skip (1,2,3 points ) it works for me . i can login but with 2nd when start from 1st step it Throws

Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.SocketTimeoutException: timeout at point 5 (when needs to enter email)

Here is my overall code :

  WebDriver web;
    public void invokeChrome()
    {
            System.setProperty("webdriver.chrome.driver", "D:\\software testing\\chromedriver.exe");
            web = new ChromeDriver();
            web.manage().window().maximize();
            web.manage().deleteAllCookies();
            web.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
            web.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
            web.get("https://www.google.com");

    }
 void searchQuery() throws InterruptedException
   {
       web.findElement(By.name("q")).sendKeys("Gmail Login");
       Thread.sleep(2000);
       web.findElement(By.xpath("//div[@class='sbl1']")).click();

       web.findElement(By.xpath("//h3[@class='LC20lb']")).click();
       web.findElement(By.linkText("Sign in")).click();
       Thread.sleep(2000);
       web.findElement(By.xpath("//input[@type='email']")).sendKeys("xyz@gmail.com");
       web.findElement(By.xpath("//span[@class='RveJvd snByac']")).click();
       web.findElement(By.cssSelector(".A3sRAb.YKooDc .zHQkBf, .A3sRAb.YKooDc .MQL3Ob")).sendKeys("*****@");
       Thread.sleep(2000);
       web.findElement(By.xpath("//span[contains(text(), 'Next')]")).click();

   }

I am using Chromedrive 74 and selenium : 3.9.0 release

  • Have you tried with `3.9.1` or later. If I remember correctly `3.9.0` had the issue with `SocketTimeoutException`. However, as you started learning selenium, why can't you use the latest version of as of today selenium [3.141.59](https://www.seleniumhq.org/download/) – supputuri Jul 05 '19 at 20:41
  • okay trying again with latest , that you for your suggestion. i will let you know shortly – Awais Arshad Jul 05 '19 at 20:48
  • unfortunately i got the same error with latest version as well . `Exception in thread "main" org.openqa.selenium.WebDriverException: java.net.SocketTimeoutException: Read timed out` – Awais Arshad Jul 05 '19 at 20:50

1 Answers1

1

I figured out the solution by myself . just though may be it will help someone in future. okay the problem was

   <a href="SIGN IN Page" target="_blank">

Because when new tab opens , Webdriver needs to shift control from old tab to new tab . like this :

   WebElement link =   web.findElement(By.linkText("Sign in"));
   String l = link.getAttribute("href");
   web.get(l);