0

I want to click on "Open device Access" button but when i click on accordion, the button "Open device access" is not displayed. I think that JavaScript is not active because the transfer between "display none" and "display block" doesn't exist. The button "Open device acces" is not visible after a click on accordion.

HTML code :

<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" style="display: none;">
        <div class="submit">
        <input type="button" onclick="onOpenSessionClick()" value="Open device access">
    </div>
</div>

JavaScript code :

driver.findElement(By.xpath("//a[@href='/mybox/devices/satellite.php']")).click();
Thread.sleep(5000);
driver.findElement(By.id("device_hmi_content_22")).click();
WebElement element2 = driver.findElement(By.xpath("//input[@value='Open device access']"));

if (isElementPresent(By.xpath("//input[@value='Open device access']")))
{
    driver.findElement(By.xpath("//input[@value='Open device access']")).click();
Cheesebaron
  • 24,131
  • 15
  • 66
  • 118
Julien P.
  • 91
  • 1
  • 2
  • 8
  • Are you able to share the webpage which you are testing on? – ddavison May 16 '13 at 14:36
  • It sounds like either `1)` the click on the according is not working. The click appears to be handled by JavaScript but how is that done exactly? Is there something like jQuery that binds clicks on that div to code that shows the accContent div? OR `2)` Your code to click on the button is happening to quickly after you click on the div that will show it. Try putting a `sleep` after you click on the accContent div and see if that helps. – ragamufin May 17 '13 at 02:10
  • @sircapsalot I shared the rest of the useful part is I can not quite confidential. – Julien P. May 17 '13 at 08:39
  • @ragamufin I added a sleep after the execution of javascript but nothing changes JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("window.document.getElementsByClassName('accContent accContentClosed')[0].style.display='block';"); Thread.sleep(5000); – Julien P. May 17 '13 at 08:39
  • Does the click on `device_hmi_content_22` actually work? What about if you sleep after that, so `driver.findElement(By.id("device_hmi_content_22")).click(); Thread.sleep(5000);`? – ragamufin May 20 '13 at 04:49

1 Answers1

0

May be you could use js executor to display those button:

driver.findElement(By.xpath("//a[@href='/mybox/devices/satellite.php']")).click();
        Thread.sleep(5000);
        driver.findElement(By.id("device_hmi_content_22")).click();

        JavascriptExecutor jse = (JavascriptExecutor)driver;
        jse.executeScript("window.document.getElementsByClassName('accContent accContentClosed')[0].style.display='block';");

        WebElement element2 = driver.findElement(By.xpath("//input[@value='Open device access']"));

       if ( isElementPresent(By.xpath("//input[@value='Open device access']")) )
                {
                   driver.findElement(By.xpath("//input[@value='Open device access']")).click();
ievche
  • 1,735
  • 14
  • 22
  • Thanks This is not possible without forcing the Javasript, it should not be automatic? – Julien P. May 16 '13 at 17:21
  • I have test your script and the button is always not visible. I don't understand... – Julien P. May 17 '13 at 08:24
  • What about style attribute, was it changed to "display: block"? – ievche May 17 '13 at 08:49
  • Device Access

    – Julien P. May 17 '13 at 12:59
  • Only idea that i have is to click this button using jsClick [howToPerformJsClick]("http://stackoverflow.com/questions/11947832/how-to-click-a-button-in-webdriver-using-javascript"). I have no ideas why those button is not displayed after above script. You should investigate manually, what was changed in html after button "Open device access" is displayed. – ievche May 17 '13 at 14:07
  • When i use this script, i have build failure: JavascriptExecutor jse = (JavascriptExecutor)driver; jse.executeScript("document.getElementById('device_hmi_content_22').click();"); – Julien P. May 21 '13 at 08:31
  • Capabilities [{platform=LINUX, javascriptEnabled=true, acceptSslCerts=true, brow serName=firefox, rotatable=false, locationContextEnabled=true, version=3.5.16, c ssSelectorsEnabled=true, handlesAlerts=true, nativeEvents=false, webStorageEnabl ed=true, applicationCacheEnabled=true, takesScreenshot=true}] – Julien P. May 21 '13 at 08:50
  • Try to replace "document" with "window.document". – ievche May 21 '13 at 09:40
  • Thanks for your help but : – Julien P. May 22 '13 at 08:07
  • Could be you should click on other element. – ievche May 22 '13 at 08:10
  • I don't should click on other element, my test is to click on this button. This is a log firefox_console for the click on accordeon webdriver [130522 10:30:03.83] [ 20.073s] [webdriver] Falling back to synthesized click webdriver [130522 10:30:03.87] [ 20.192s] [webdriver] About to do a bot.action.click on [object XPCNativeWrapper [object HTMLDivElement]] webdriver [130522 10:30:03.92] [ 20.165s] [webdriver] Not loading document anymore. – Julien P. May 22 '13 at 08:35
  • I thought you need to click on "Open device access" button – ievche May 22 '13 at 09:46
  • Yes that's right. I click on accordeon "Device Access" then on the button "Open device Access" – Julien P. May 22 '13 at 10:05
  • I'm succes. On Debian serveur Firefox must be "Firefox 12" thanks for your help cherya – Julien P. May 22 '13 at 14:45