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();
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With