Example usage for org.openqa.selenium InvalidElementStateException InvalidElementStateException

List of usage examples for org.openqa.selenium InvalidElementStateException InvalidElementStateException

Introduction

In this page you can find the example usage for org.openqa.selenium InvalidElementStateException InvalidElementStateException.

Prototype

public InvalidElementStateException() 

Source Link

Usage

From source file:com.hotwire.test.steps.search.air.AirSearchModelWebApp.java

License:Open Source License

@Override
public void verifySuggestedLocation(String number, String expectedAutoCompleteItem, String style,
        String click) {//  www  . ja v  a2s . c o  m
    try {
        //Let's give a little bit time for the rendering auto-complete layer  - 0.2 sec
        Thread.sleep(200);
    } catch (InterruptedException e) {
        //...
    }
    AirSearchFragment airSearchFragment = new AirSearchFragment(getWebdriverInstance());
    airSearchFragment.isAutoCompleteDisplayed();
    LOGGER.info("Auto-complete is visible");

    ArrayList<String> autocomleteContents = airSearchFragment.getAutoCompleteContents();
    ArrayList<String> autocompleteAttributes = airSearchFragment.getAttibutesForAutocomplete("class");
    List<WebElement> autocomleteElements = airSearchFragment.getAutocompleteElements();

    Integer i = autocomleteContents.indexOf(expectedAutoCompleteItem);

    if (number != null) {
        if (number.trim().equals("first")) {
            assertThat(i == 0).as("First auto-complete item is : " + expectedAutoCompleteItem).isTrue();
        } else if (number.trim().equals("second")) {
            assertThat(i == 1).as("Second auto-complete item is : " + expectedAutoCompleteItem).isTrue();
        } else if (number.trim().equals("third")) {
            assertThat(i == 2).as("Third auto-complete item is : " + expectedAutoCompleteItem).isTrue();
        }
    } else {
        assertThat(i != -1).isTrue();
    }

    if (style != null) {
        if (style.trim().equals("underlined and highlighted")) {
            assertThat(autocompleteAttributes.get(i).contains("yui-ac-highlight"))
                    .as("N" + i.toString() + " auto-complete item is highlighted and underlined").isTrue();
        }
    }

    if (click != null) {
        if (click.trim().equals("and I click it")) {
            autocomleteElements.get(i).click();
            try {
                airSearchFragment.isAutoCompleteDisplayed();
                throw new InvalidElementStateException();
            } catch (NullPointerException e) {
                LOGGER.info("Auto-complete is invisible");
            }
        }
    }
}

From source file:com.hotwire.test.steps.search.air.AirSearchModelWebApp.java

License:Open Source License

@Override
public void verifyDisambiguationLayerIsVisible() {
    AirSearchFragment airSearchFragment = new AirSearchFragment(getWebdriverInstance());
    try {/* w ww  . java  2s . co  m*/
        WebElementAssert.assertThat(airSearchFragment.getAutoComplete().findElement(By.xpath("..//../div")))
                .isNotHidden().isDisplayed().textContains("Choose a");

    } catch (NullPointerException e) {
        throw new InvalidElementStateException();
    }
}

From source file:com.hotwire.test.steps.search.car.CarSearchModelWebApp.java

License:Open Source License

@Override
public void verifySuggestedLocation(String number, String expectedAutoCompleteItem, String style,
        String click) {/* w w  w.  j a v a2  s  .c om*/
    CarSearchFragment carSearchFragment = new CarSearchFragment(getWebdriverInstance());
    carSearchFragment.isAutoCompleteDisplayed();
    LOGGER.info("Auto-complete is visible");

    ArrayList<String> autocomleteContents = carSearchFragment.getAutocomleteContents();
    ArrayList<String> autocompleteAttributes = carSearchFragment.getAttibutesForAutocomplete("class");
    List<WebElement> autocomleteElements = carSearchFragment.getAutocompleteElements();

    Integer i = autocomleteContents.indexOf(expectedAutoCompleteItem);

    if (number != null) {
        if (number.trim().equals("first")) {
            assertThat(i == 0).as("First auto-complete item is : " + expectedAutoCompleteItem).isTrue();
        } else if (number.trim().equals("second")) {
            assertThat(i == 1).as("Second auto-complete item is : " + expectedAutoCompleteItem).isTrue();
        } else if (number.trim().equals("third")) {
            assertThat(i == 2).as("Third auto-complete item is : " + expectedAutoCompleteItem).isTrue();
        }
    } else {
        assertThat(i != -1).isTrue();
    }

    if (style != null) {
        if (style.trim().equals("underlined and highlighted")) {
            assertThat(autocompleteAttributes.get(i).contains("yui-ac-highlight"))
                    .as("N" + i.toString() + " auto-complete item is highlighted and underlined").isTrue();
        }
    }

    if (click != null) {
        if (click.trim().equals("and I click it")) {
            autocomleteElements.get(i).click();

            try {
                carSearchFragment.isAutoCompleteDisplayed();
                throw new InvalidElementStateException();
            } catch (TimeoutException e) {
                LOGGER.info("Auto-complete is invisible");
            }
            // This is a hack. For some reason, focus is still on this element and typing start date appends to
            // this element instead of the start date element. Attempt to send tab key to get off this element.
            carSearchFragment.getStartLocation().sendKeys(Keys.TAB);
        }
    }
}

From source file:com.hotwire.test.steps.search.hotel.HotelSearchModelWebApp.java

License:Open Source License

@Override
public void verifySuggestedLocation(String number, String expectedAutoCompleteItem, String style,
        String click) {/* ww  w  . j a va2  s  .c  o m*/
    HotelSearchFragment hotelSearchFragment = new HotelSearchFragment(getWebdriverInstance());
    hotelSearchFragment.isAutoCompleteDisplayed();
    LOGGER.info("Auto-complete is visible");

    ArrayList<String> autocomleteContents = hotelSearchFragment.getAutocompleteContents();
    ArrayList<String> autocompleteAttributes = hotelSearchFragment.getAttibutesForAutocomplete("class");
    List<WebElement> autocomleteElements = hotelSearchFragment.getAutocompleteElements();

    Integer i;
    i = autocomleteContents.indexOf(expectedAutoCompleteItem);

    if (number != null) {
        if (number.trim().equals("first")) {
            assertThat(i == 0).as("First auto-complete item is : " + expectedAutoCompleteItem).isTrue();
        }
    } else {
        assertThat(i != -1).isTrue();
    }

    if (style != null) {
        if (style.trim().equals("underlined and highlighted")) {
            assertThat(autocompleteAttributes.get(i).contains("yui-ac-highlight"))
                    .as("N" + i.toString() + " auto-complete item is highlighted and underlined").isTrue();
        }
    }

    if (click != null) {
        if (click.trim().equals("and I click it")) {
            autocomleteElements.get(i).click();

            try {
                hotelSearchFragment.isAutoCompleteDisplayed();
                throw new InvalidElementStateException();
            } catch (TimeoutException e) {
                LOGGER.info("Auto-complete is invisible");
            }
            // This is a hack. For some reason, focus is still on this element and typing start date appends to
            // this element instead of the start date element. Attempt to send tab key to get off this element.
            hotelSearchFragment.getDestCity().sendKeys(Keys.TAB);
        }
    }

}