我想从下面的网站使用Selenium与Java(3.3.0和Java版本“1.8.0_66”)点击日历。咏叹调隐藏的跨度/按钮可防止获取元素 - 硒
https://www.cathaypacific.com/cx/en_US.html
目标被点击 - 机票 - 单程 - “出发打开”按钮 不管,我试了一下可能的选项 - by.id,by.xpath和行动,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。
这是否与跨区域的'aria-hidden'= true属性有关?我们应该如何处理'隐藏咏叹调'并点击按钮?
完美!它的工作..谢谢。 顺便说一下,这个XPath看起来像嵌套的xpath,不仅我们指的是两个位置,即// div [..] // button [..],还嵌套了starts-with。对我来说很好的学习..谢谢 –