1

The thing what I wanted to do is Automate Gmail Login page on Firefox by using Selenium Web Driver. I was blocked near the locating link of gmail. I tried the correct answer of This. but it gives this error:

WAIT_TIME cannot be resolved or is not a field

I use java with eclipse. My code is as follows:

package Gmail;

import java.sql.Time;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import bsh.org.objectweb.asm.Constants;

public class GmailLogin {

    public static void main(String[] args) {
        CharSequence[] g = {"gmail"};
        WebDriver driver = new FirefoxDriver();
        driver.get("https://www.google.lk/");
        driver.findElement(By.id("lst-ib")).sendKeys(g);
        driver.findElement(By.name("btnG")).click();    
        driver.findElement(By.linkText("Gmail - Google")).click();
        Time timeSpan = new Time(3);
        driver.manage().timeouts().ImplicitlyWait(timeSpan.FromSeconds(Constants.WAIT_TIME));

    }

}

The link I found by using FirePath and Firebug is this;

<a onmousedown="return rwt(this,'','','','1','AFQjCNExwdtj2geSDAkwzEypo2w-h0HAPg','','0ahUKEwjGg77e_JTKAhWTHo4KHcIkAd8QFggZMAA','','',event)" href="https://mail.google.com/">Gmail - Google</a>

Can someone help for me to get the right code to open the Gmail Login by clicking on "Gmail - Google".

This is the error I got.

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
WAIT_TIME cannot be resolved or is not a field

    at Gmail.GmailLogin.main(GmailLogin.java:19)
  • If someone can give the answer with the code, its better – Tharindu Kandegedara Jan 7 '16 at 3:46
0

First things first : You don't automate the browser. I have edited it to mention correctly.

Second, for your issue, this is because Constants.WAIT_TIME is not mapped to any time interval. The script wouldn't know what time period to wait.

try using this

driver.manage().timeouts().ImplicitlyWait(30,TimeUnit.SECONDS);

if you want to wait for 30 seconds.

Edit : I wrote this and tested this code for entering a simple Gmail id and login and it works perfectly fine.

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Gmail {
    public static void main(String[] args) {
        WebDriver driver = new FirefoxDriver();
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
        driver.get("https://www.google.lk/");
        driver.findElement(By.linkText("Gmail")).click();
        driver.findElement(By.id("Email")).sendKeys("xyz@gmail.com");
        driver.findElement(By.id("next")).click();
        driver.findElement(By.id("Passwd")).sendKeys("abcdefghh");
        driver.findElement(By.id("signIn")).click();

        driver.quit();

        // TODO Auto-generated method stub
    }

}

Tested on Ubuntu machine on Firefox version 43.0 with Selenium 2.48.2

  • I tried it like this. import java.util.concurrent.TimeUnit; driver.findElement(By.linkText("Gmail - Google")).click(); driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS); nothing errors are appeared in the code. but it doesn't work.. – Tharindu Kandegedara Jan 7 '16 at 3:11
  • pls mention how to map the WAIT_TIME to a time interval. using the code. – Tharindu Kandegedara Jan 7 '16 at 3:43
  • Check my edited answer. – demouser123 Jan 7 '16 at 4:51
0

First of all implicit wait method should be declared before findElement() bcz findElement method uses implicitWait() method to search for web elements till the specified time... And it is good to use direct link "www.gmail.com" to login so that u can reduce ur codes... Learn more about locators of webdriver and proceed...

  • I can do it here, But I needed to learn those things. How to write the code for clickAndWait. for example when I go inside of a web site, I have to use that. – Tharindu Kandegedara Jan 7 '16 at 3:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.