Bob Reynolds Bob Reynolds - 5 months ago 11x
Java Question

Selenieum and hidden form, non determinist execution

i want to test a javaEE application server and i want to test it with selenium, when Selenium connect he have to go trough 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 hidden name="formLogout" method="POST" action="/app/">
<input type="hidden" name="home" value="false">

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 follwing 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 {

JavascriptExecutor js = (JavascriptExecutor) driver;

js.executeScript("document.getElementsByName('formLogin')[0].checked = true;");
js.executeScript("document.getElementsByName('formLogout')[0].checked = true;");

driver.findElement(By.xpath("//a[contains(@href, '#')]")).click();
} finally {


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 ? Plz help.

EDIT 1: I edited the code, i'm sure of it. When i spamm 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.


It looks like your xpath selectors are too general.

You can wait for an element to be visible with


I'm confused what you're trying to do in your method. Your java code doesn't match your provided html. Please provide a more complete html example.

Using your current java code, you could wait for all elements like this:

// define reusable Bys
By usernameInput = By.xpath("//input");
By passwordInput = By.xpath("//div[2]/div/div/input");
By submitButton = By.xpath("//a[contains(@href, '#')]");

// wait for all elements to be visible
// clear username field and type username
// clear password field and type password
// submit the form