【发布时间】:2017-09-16 11:16:08
【问题描述】:
我正在尝试使用 Selenium 和 Java(3.3.0 和 java 版本“1.8.0_66”)从以下网站单击日历。
https://www.cathaypacific.com/cx/en_US.html
要点击的目标 - 航班 - 一种方式 - “起飞”按钮 不管我尝试了哪些可能的选项——by.id、by.xpath 和 Actions、EventFiringMouse 等,这个按钮根本不会被点击。
"<div class="button-date-picker-wrapper field-group cx-inputfield">
<span class="field-label input-filled" aria-hidden="true">Departing on</span>
<button id="dppju1sm" class="button-date-picker field-button from-button has-dates input-filled" role="link" type="button" data-ui-overlay-shared="true" data-ui-overlay-id="trip-dates-picker" aria-expanded="false" aria-label="Departing on Thursday 20 April 2017">
</div>"
private static void pickFlightCode() throws InterruptedException {
WebElement element = driver.findElement(By.xpath("//div[1]/button[starts-with(@id,'dp')]"));
//wdwait.until(ExpectedConditions.elementToBeClickable(element));
Actions actions=new Actions(driver);
actions.moveToElement(element).moveToElement(driver.findElement(By.xpath("//div[1]/button[starts-with(@id,'dp')]"))).click().build().perform();
element = driver.findElement(By.xpath("//div[1]/button[starts-with(@id,'dp')]"));
System.out.println(element.getAttribute("aria-hidden"));
}
(或)
driver.findElement(By.xpath("//div[1]/button[starts-with(@id,'dp')]")).click();
String js = "document.getElementById("field-label").style.display = "block";';
arguments[0].style.visibility='visible';";
上面的代码不起作用,我收到“元素不可见”异常。 Driver.findElement - isEnabled 返回 true,Driver.findElement - isDisplayed 返回 false。
这与 span 中的 'aria-hidden'=true 属性有关吗?我们应该如何处理'aria-hidden'并点击按钮?
【问题讨论】: