我试图使用Selenium with 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'并点击按钮?
3 回答
为了达到所需的控制,您可以使用其容器 . 因此,请尝试以下方法
让我知道,它是否适合你 .
试试这个按钮的xpath -
我在Firefox中检查了这个,它对我有用 .
尝试使用此JavaScript代码以启用所选元素的可见性 .