0
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.datatransfer.StringSelection;
import java.awt.event.KeyEvent;

import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class EmployeeTest {

@FindBy(xpath="//input[@id='email']")
public static WebElement emailIDField;

@FindBy(xpath="//input[@id='password']")
public static WebElement passwordField;

@FindBy(xpath="//a[@id='submitButton']")
public static WebElement loginButton;

static String subscriptionsAndBillingTabXpath="//a[contains(text(),'Silling')]";
@FindBy(xpath="//a[contains(text(),'Silling')]")
public static WebElement subscriptionsAndBillingTab;

public static WebDriver driver;

public static WebDriverWait wait;

public static void main(String[] args) {
    // TODO Auto-generated method stub
    driver = new FirefoxDriver();

    driver.get("http://url.domain.com");

    wait.until(ExpectedConditions.visibilityOf(emailIDField));
    emailIDField.click();
    emailIDField.sendKeys("abc@abc.com");

    wait.until(ExpectedConditions.visibilityOf(passwordField));
    passwordField.click();
    passwordField.sendKeys("xyz");

    loginButton.click();

    wait.until(ExpectedConditions.visibilityOf(subscriptionsAndBillingTab));
    if(driver.findElements(By.xpath(subscriptionsAndBillingTabXpath)).size()!=0)
        System.out.println("Login successful!");

    else
        System.out.println("Failed to login!");
    driver.close();

}

}

exception seen is below,

Exception in thread "main" java.lang.NullPointerException
    at org.openqa.selenium.support.ui.ExpectedConditions.elementIfVisible(ExpectedConditions.java:227)
    at org.openqa.selenium.support.ui.ExpectedConditions.access$1(ExpectedConditions.java:226)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:213)
    at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:1)
    at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:208)
    at EmployeeTest.main(EmployeeTest.java:43)
Jens
  • 67,715
  • 15
  • 98
  • 113
Sandeep
  • 153
  • 2
  • 4
  • 16

1 Answers1

1

You havent initialized wait so its null and throwing NPE on following line

wait.until(ExpectedConditions.visibilityOf(emailIDField));

You can initialize it as

wait = new WebDriverWait(driver, 15);

here 15 is time out value in seconds, you can change it as per your needs. Also you can use other constructors as given in the documentation.

Ajinkya
  • 22,324
  • 33
  • 110
  • 161