I am facing an issue with my Java program and Selenium WebDriver. The script I have does not detect the button "Open device access" because its style is set to "display: none".
Usually, clicking on "Device Access" triggers JavaScript to display the "Open Access device" button. However, it seems that my Firefox WebDriver is not supporting JavaScript. How can I resolve this?
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 (Before accordion): "+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 {
// Code to handle if element is not present
}
Although I prefer not to use JavaScript directly in my code, how can I enable JavaScript on my Firefox WebDriver?
The button "Open device access" is currently invisible:
<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>
Since the "Open device access" button is not visible, how can I interact with it and make it visible?
Thank you for any assistance provided.