Reputation: 91
I have program with Java and I use Selenium WebDriver. But my script doesn't see the button "Open device access" because it is "display : none".
Normally, when I click on "Device Access", the "Open Access device" button appears with the JavaScript. My Firefox WebDriver does not seem to support JavaScript, how can I operate it?
driver.get(baseUrl);
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys("admin");
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys("XXX");
driver.findElement(By.name("btnlogin")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[@href='/mybox/devices/overview.php']")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//a[@href='/mybox/devices/satellite.php']")).click();
Thread.sleep(5000);
WebElement element = driver.findElement(By.xpath("//input[@value='Open device access']"));
System.out.println("Element display (Avant accordéon): "+element.isDisplayed()+"");
driver.findElement(By.id("device_hmi_content_22")).click();
WebElement element2 = driver.findElement(By.xpath("//input[@value='Open device access']"));
System.out.println("Element display (open): "+element2.isDisplayed()+"");
if (isElementPresent(By.xpath("//input[@value='Close device access']")) ) {
driver.findElement(By.xpath("//input[@value='Close device access']")).click();
driver.findElement(By.xpath("//input[@value='Open device access']")).click();
Thread.sleep(5000);
assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div/p/span")));
assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div[2]/input")));
assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div[2]/input[2]")));
Thread.sleep(3000);
driver.findElement(By.xpath("//input[@value='Close device access']")).click();
Thread.sleep(5000);
} else {
// driver.findElement(By.xpath("//input[@value='Open device access']")).click();
// Thread.sleep(5000);
// assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div/p/span")));
// assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div[2]/input")));
// assertTrue(isElementPresent(By.xpath("/html/body/div[2]/div[3]/div[3]/div[2]/div/div[2]/div[2]/div/div[6]/div/div/div[2]/input[2]")));
// Thread.sleep(3000);
// driver.findElement(By.xpath("//input[@value='Close device access']")).click();
// Thread.sleep(5000);
}
I don't want to program with javascript but I want to activate JavaScript on my Firefox WebDriver.
The button is not visible:
<div id="device_hmi_content_22"> <
div id="accordion_device_hmi_22" class="accordion">
<h2 class="accHeadline accHeadlineClosed">Device Access</h2>
<div class="accContent accContentClosed ">
<div class="submit">
<input type="button" onclick="onOpenSessionClick()" value="Open device access">
</div>
</div>
</div>
The button "open device access" is "not visible", so how can I click on it? How can I make it visible?
Thanks for your help.
Upvotes: 1
Views: 1976
Reputation: 491
Javascript works out-of-the-box with Selenium WebDrivers, includeing the Firefox driver. The issue is not that javascript is not running. If you want to confirm this just open the console during a long sleep and run alert();
. Or, to dash away all doubts run this in your test:
driver.get(baseUrl);
driver.execute('alert();');
You should see the standard browser alert indicating that javascript is indeed working properly and your issue is stemming from somewhere else.
I've personally had issues where a click into an element is "stolen" by an element above it, often this can happen if you have fixed-position elements. If you think this could be an issue, look into setting elementScrollBehavior
to 1.
Upvotes: 1