0

I'm trying to log into a website with HtmlUnitDriver and I keep getting a java.lang.error.

Ive added multiple jars to fix my com.gargoylesoftware.htmlunit.browserversion error which fixed that but caused another problem.

import org.jsoup.Connection;
import org.jsoup.Connection.Response;
import org.jsoup.Connection.Method;
import org.jsoup.Jsoup;  
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import java.io.IOException;
import java.net.CookieHandler;
import java.net.CookieManager;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.HasInputDevices;
public class selenium
public static void main ( String[] args ) throws IOException {
    HtmlUnitDriver driver = new HtmlUnitDriver(true); // line that shows a error
    String baseUrl = "website";

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

    driver.get(baseUrl);

    driver.findElement(By.name("username")).clear();
    driver.findElement(By.name("username")).sendKeys("username");
    driver.findElement(By.name("password")).clear();
    driver.findElement(By.name("password")).sendKeys("password");
    driver.findElement(By.cssSelector("input[type='submit']")).click();

Exception in thread "main" java.lang.Error: Unresolved compilation problems: HtmlUnitDriver cannot be resolved to a type HtmlUnitDriver cannot be resolved to a type Syntax error, insert "}" to complete ClassBody

finesse
  • 13
  • 2
  • The compiler is indicating that it can't find the class HTMLUnitDriver. Did you [download](https://github.com/SeleniumHQ/htmlunit-driver) and install it? Did you include an import statement pointing to it? – MarsAtomic Feb 10 '19 at 02:39
  • @MarsAtomic I have downloaded it, but I dont think ive included an import statement pointing to it. Could you clarify what you mean by that if possible? Thanks for the answer aswell. (unless you mean import org.openqa.selenium.htmlunit.HtmlUnitDriver;) – finesse Feb 10 '19 at 02:48
  • Post the top of the file from which you copied the code you included in your original post. I need to see everything above the first appearance of the words `public class` or `class`. Import statements are a very, very fundamental aspect of the Java language, so if you more or less don't understand Java programming, you need to be honest with me, otherwise, I'll end up talking over your head and we're not going to get anywhere. – MarsAtomic Feb 10 '19 at 03:47

0 Answers0