kumar-nitish
8/22/2017 - 6:14 PM

test.java

package github;

import org.apache.commons.io.FileUtils;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class GitHub4477 {

  private WebDriver driver;

  @BeforeMethod
  public void setUp() throws Exception {
    ChromeOptions chromeOptions = new ChromeOptions();
    //todo Change your chrome driver path
    System.setProperty("webdriver.chrome.driver", Thread.currentThread().getContextClassLoader()
        .getResource("chromedriver.exe").getFile());
    chromeOptions.addArguments("--headless");
    driver = new ChromeDriver(chromeOptions);
  }

  @Test
  public void testIssue4477() throws Exception {
    // todo change it to test html page 
    driver.get("file:///C:/Users/nitish/Desktop/test.html");
    WebDriverWait wait = new WebDriverWait(driver, 10);
    wait.until(
        ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='form']/p[1]/label")));
    System.out.println(
        "Label text : " + driver.findElement(By.xpath("//*[@id='form']/p[1]/label")).getText());
  }

  @AfterMethod
  public void tearDown() throws Exception {
    driver.close();
    driver.quit();
  }
}