0

我想单击“打开设备访问”按钮,但是当我单击手风琴时,未显示“打开设备访问”按钮。我认为 JavaScript 不活跃,因为“不显示”和“显示块”之间的传输不存在。单击手风琴后,“打开设备访问权限”按钮不可见。

HTML 代码:

<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 代码:

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();
4

1 回答 1

0

也许你可以使用 js 执行器来显示这些按钮:

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();
于 2013-05-16T14:57:11.503 回答