I want to test a javaEE application server and I want to test it with Selenium, when Selenium connect he have to go through a login page, but the form of this login page is hidden so I'm trying to type text in a form that the hidden property with Selenium.
<form hidden name="formLogin" method="POST" action="/app/">
<input type="hidden" name="home" value="true">
</form>
<form hidden name="formLogout" method="POST" action="/app/">
<input type="hidden" name="home" value="false">
</form>
After reading this post, post on how to force selenium to locate the hidden field, I thought I had the solution, but it starts to drive me crazy.
I have the following code :
public class SeleniumTestKheops {
static WebDriver driver;
static Wait<WebDriver> wait;
public static void main(String[] args) throws InterruptedException {
driver = new FirefoxDriver();
wait= new WebDriverWait(driver, 30);
final String url = "https://localhost:8444/app/";
try {
driver.navigate().to(url);
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementsByName('formLogin')[0].checked = true;");
js.executeScript("document.getElementsByName('formLogout')[0].checked = true;");
driver.findElement(By.xpath("//input")).clear();
driver.findElement(By.xpath("//input")).sendKeys("root");
driver.findElement(By.xpath("//div[2]/div/div/input")).clear();
driver.findElement(By.xpath("//div[2]/div/div/input")).sendKeys("pass");
driver.findElement(By.xpath("//a[contains(@href, '#')]")).click();
} finally {
//driver.close();
}
}
}
But when I run it multiple time, the result is different, sometimes it works, and most of the times I have :
Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
I don't understand the meaning of this, I'm sure, why is this randomly working? What am I doing wrong?
EDIT 1: I edited the code, I'm sure of it. When I spam the running of this code it works 1 on 5 times. I still don't know why. I'm looking for a way to check all the webelement that are visible on the page.