user1454686
user1454686

Reputation:

selenium WebDriver, work without any internet browser.

I have simple selenium's class. it works very well. Now i'm interested in, how to do the same sing in console mode. In the other words. I need a result (in the code, if request was succeeded or not.) I don't need to show in a web browser. if everything is well i need a return value, if not another return value (something like true or false);

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

 WebDriver driver;
 WebElement loginInput;
 WebElement passwordInput;
 WebElement loginSubmit;
 driver = new FirefoxDriver();     

 driver.get("URL");
 loginInput = driver.findElement(By.id("id"));

 loginInput.sendKeys("ninotyesh");
 passwordInput =driver.findElement(By.id("id"));
 passwordInput.sendKeys("key");
 loginSubmit = driver.findElement(By.id("id"));
 loginSubmit.click();

Upvotes: 3

Views: 3096

Answers (1)

Pavel Janicek
Pavel Janicek

Reputation: 14738

You might consider running your script in HTMLUnitDriver - see short help about it

And at end of your code I would do check for some element which should be present after successful login and print out TRUE in case the driver finds it.

Upvotes: 5

Related Questions