Here is my basic code for launching HTMLUnit browser and getting the title. while running the code i am getting the title as null and later it is throwing the following execpetion:
Jars used:
- htmlunit-driver-2.33.0-jar-with-dependencies.jar
- selenium-server-standalone-3.14.0.jar
Code trials:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
public class HtmlUnitDriverTest {
public static void main(String[] args) throws InterruptedException {
WebDriver driver = new HtmlUnitDriver();
Thread.sleep(5000);
driver.get("https://google.com");
System.out.println(driver.getTitle());
driver.findElement(By.name("q")).sendKeys("testing");
}
}
O/p:
Exception in thread "main" java.lang.IllegalStateException: Unable to locate element by name for com.gargoylesoftware.htmlunit.UnexpectedPage@2e32ccc5
at org.openqa.selenium.htmlunit.HtmlUnitDriver.findElementByName(HtmlUnitDriver.java:1285)