我有 Java 程序,我使用 Selenium WebDriver。但是我的脚本没有看到“打开设备访问”按钮,因为它是“显示:无”。
通常,当我单击“设备访问”时,会出现带有 JavaScript 的“打开访问设备”按钮。我的 Firefox WebDriver 似乎不支持 JavaScript,如何操作?
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);
}
我不想用 javascript 编程,但我想在我的 Firefox WebDriver 上激活 JavaScript。
该按钮不可见:
<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>
“打开设备访问”按钮是“不可见”的,怎么才能点击呢?我怎样才能让它可见?
谢谢你的帮助。