Aim: To use headless option for selenium testing of login page.(HTMLUnitDriver preferable)
I am trying to automate a login to a site using HTMLUnitDriver.
When I sendKeys to an element, it throws an error.
HtmlUnitDriver driver = new HtmlUnitDriver();
driver.manage().timeouts().implicitlyWait(2, TimeUnit.SECONDS);
driver.get("https://bigData/login.jsp");
WebDriverWait usernameWait = new WebDriverWait(driver, 3);
usernameWait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input[@id=\"username\"]")));
driver.findElement(By.xpath("//input[@id=\"username\"]")).sendKeys("admin");
Error:
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: You may only interact with visible elements
I tried the same with ChromeDriver. It works fine! It didn't throw this exception. But I could not use the headless option in it.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
WebDriver driver = new ChromeDriver(chromeOptions);
returns,
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for presence of element located by: By.xpath: //input[@id="username"] (tried for 3 second(s) with 500 milliseconds interval)
Works fine, only when chromeOptions is not defined while initializing chromeDriver.
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
WebDriver driver = new ChromeDriver();
Please guide me what could be these scenarios/suggest an alternative?