Search in sources :

Example 1 with UnexpectedTagNameException

use of org.openqa.selenium.support.ui.UnexpectedTagNameException in project alex by LearnLib.

the class SelectAction method execute.

@Override
public ExecuteResult execute(WebSiteConnector connector) {
    final WebElementLocator nodeWithVariables = new WebElementLocator(insertVariableValues(node.getSelector()), node.getType());
    try {
        final String valueWithVariables = insertVariableValues(value);
        final WebElement selectElement = connector.getElement(nodeWithVariables);
        final Select select = new Select(selectElement);
        switch(selectBy) {
            case VALUE:
                select.selectByValue(valueWithVariables);
                break;
            case TEXT:
                select.selectByVisibleText(valueWithVariables);
                break;
            case INDEX:
                select.selectByIndex(Integer.parseInt(value));
                break;
            default:
                select.selectByIndex(0);
                break;
        }
        logger.info(LoggerMarkers.LEARNER, "Selected '{}' of '{}' by '{}'.", value, nodeWithVariables, selectBy);
        return getSuccessOutput();
    } catch (NoSuchElementException | NumberFormatException | UnexpectedTagNameException e) {
        logger.info(LoggerMarkers.LEARNER, "Could not select '{}' of '{}' by '{}'.", value, nodeWithVariables, selectBy, e);
        return getFailedOutput();
    }
}
Also used : UnexpectedTagNameException(org.openqa.selenium.support.ui.UnexpectedTagNameException) WebElementLocator(de.learnlib.alex.data.entities.WebElementLocator) Select(org.openqa.selenium.support.ui.Select) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Aggregations

WebElementLocator (de.learnlib.alex.data.entities.WebElementLocator)1 NoSuchElementException (org.openqa.selenium.NoSuchElementException)1 WebElement (org.openqa.selenium.WebElement)1 Select (org.openqa.selenium.support.ui.Select)1 UnexpectedTagNameException (org.openqa.selenium.support.ui.UnexpectedTagNameException)1