1
votes

I am trying to click a calendar from the following website using Selenium with Java (3.3.0 and java version "1.8.0_66").

https://www.cathaypacific.com/cx/en_US.html

Target to be clicked - Flights - One Way - 'Departing On' button No matter, what possible options I tried - by.id, by.xpath and Actions, EventFiringMouse etc., this button does not get clicked at all.

"<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"));

}

(or)

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';";

The above code does not work and I am getting 'Element Not Visible' Exception. Driver.findElement - isEnabled returns true and Driver.findElement - isDisplayed returns false.

Is this something to do with the 'aria-hidden'=true attribute in span? How should we handle 'aria-hidden' and click on the button?

3

3 Answers

0
votes

Try this for the button's xpath -

//div[@class = 'dates-picker-wrapper splited-date-picker flight-datepicker']/div[1]/button

I have checked this in Firefox and it working for me.

0
votes

In order to reach to the required control, you can make use of its container. Hence, try following:

//div[@data-date-picker-id='book-trip']//button[starts-with(@id,'dp') and starts-with(@aria-label, 'Departing on ')]

Let me know, whether it works for you.

0
votes

Try this JavaScript code to enable visibility of selected element.

WebElement element = driver.findElement(By.xpath("Element Xpath"));
String js = "arguments[0].style.height='auto'; arguments[0].style.visibility='visible';";
((JavascriptExecutor) driver).executeScript(js, elem);