1

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".

http://clip2net.com/s/53N136

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.

6
  • Screenshots don't help with Selenium/WebDriver problems. You should include the HTML in your question instead. Commented May 14, 2013 at 10:55
  • What happens when you run your code? Commented May 14, 2013 at 10:56
  • When i execute my code in local it's good but with a server my test is failed because "element 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> Commented May 14, 2013 at 11:25
  • After editing your code, i'm pretty sure the problem might not be JavaScript at all. You have serious issues, try making some more precise xpaths or css selectors. Commented May 14, 2013 at 13:13
  • Also, those sleeps() don't guarantee you the element will be ready to get clicked, not to mention the time waste. If you pass through the if, that takes ~30 seconds to run a small portion of code. With all that time you'd be better testing by yourself. Commented May 14, 2013 at 13:15

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.