Example usage for org.openqa.selenium WebElement isEnabled

List of usage examples for org.openqa.selenium WebElement isEnabled

Introduction

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

Prototype

boolean isEnabled();

Source Link

Document

Is the element currently enabled or not?

Usage

From source file:edu.umd.cs.guitar.crawljax.ripper.plugin.GUITARWebEventMonitorPlugin.java

License:Open Source License

/**
 * Collect all events available in the current session
 * @param session// w  ww  .jav  a  2  s .  co  m
 */
private Map<WebElement, Set<Class<? extends GEvent>>> collectEventableWebElmenent(CrawlSession session) {
    Map<WebElement, Set<Class<? extends GEvent>>> eventActionMap = new HashMap<WebElement, Set<Class<? extends GEvent>>>();

    for (Class<? extends GEvent> gEvent : manager.getSupportedEvents()) {
        // Setup event specification
        EventSpecification spec = manager.getEventSpecification(gEvent);
        try {
            List<CandidateElement> candidateList = getCandidateElementList(spec, session);
            for (CandidateElement element : candidateList) {
                EmbeddedBrowser browser = session.getBrowser();
                try {
                    WebElement webElement = browser.getWebElement(element.getIdentification());

                    // We ignore the invisible and disabled element
                    if (!webElement.isDisplayed() || !webElement.isEnabled())
                        continue;

                    Set<Class<? extends GEvent>> supportedEventSet = eventActionMap.get(webElement);

                    if (supportedEventSet == null) {
                        supportedEventSet = new HashSet<Class<? extends GEvent>>();
                    }

                    supportedEventSet.add(gEvent);
                    eventActionMap.put(webElement, supportedEventSet);

                } catch (org.openqa.selenium.NoSuchElementException noElementException) {

                    LOGGER.debug("WebElement is not accessable");
                    LOGGER.debug("Identification: " + element.getIdentification());

                }
            } // end capture all GEvent

        } catch (CrawljaxException e) {
            LOGGER.debug("CrawljaxException" + e.getMessage());
        }
    }
    return eventActionMap;
}

From source file:edu.umd.cs.guitar.model.WebEventAnalyzer.java

License:Open Source License

/**
 * Analyze a web element and extract all replayable event
 *
 * <p>/*from w ww.  j av a2 s. c om*/
 *
 * @param element
 * @return a look up table for all replayable events and widgets
 */
public GUIMap extractEvents(WebElement element) {
    GUIMap map = factory.createGUIMap();

    WidgetMapTypeWrapper widgetMap = new WidgetMapTypeWrapper(factory.createWidgetMapType());
    EventMapTypeWrapper eventMap = new EventMapTypeWrapper(factory.createEventMapType());

    // List<WebElement> children = element.findElements(By.cssSelector("*"));
    List<WebElement> children = element.findElements(By.xpath(".//*"));
    List<WebElement> childrenEnabled = new ArrayList<WebElement>();

    for (WebElement aChild : children) {
        try {
            if (!aChild.isEnabled() || !(aChild.isDisplayed()))
                continue;
        } catch (StaleElementReferenceException exception) {
            LOGGER.error(exception);
        }
        childrenEnabled.add(aChild);
    }
    children = childrenEnabled;

    LOGGER.info("TOTAL visible element to explore: " + children.size());

    for (WebElement aChild : children) {
        if (!aChild.isEnabled() || !(aChild.isDisplayed()))
            continue;
        WebComponent gComponent = new WebComponent(aChild, null, null, null);

        if (hasEventSupported(gComponent)) {
            long hashcode = getHashCode(aChild);

            String widgetID = GUITARConstants.COMPONENT_ID_PREFIX + hashcode;

            if (!widgetMap.contains(widgetID)) {
                // create lookup widget
                WidgetMapElementType widgetElement = factory.createWidgetMapElementType();
                ComponentType componentData = gComponent.extractProperties();
                ComponentTypeWrapper componentDataWrapper = new ComponentTypeWrapper(componentData);
                componentDataWrapper.addProperty(GUITARConstants.ID_TAG_NAME, widgetID);
                componentData = componentDataWrapper.getDComponentType();
                widgetElement.setComponent(componentData);
                widgetElement.setWidgetId(widgetID);

                widgetMap.getWidgetMapElement().add(widgetElement);
            }

            for (GEvent event : eventManager.getEvents()) {
                if (event.isSupportedBy(gComponent)) {
                    String eventID = GUITARConstants.EVENT_ID_PREFIX + hashcode;
                    if (!eventMap.contains(eventID)) {
                        EventType eventElement = factory.createEventType();

                        // event id 
                        eventElement.setEventId(eventID);
                        // widget id
                        eventElement.setWidgetId(widgetID);
                        // action
                        String action = event.getClass().getName();
                        eventElement.setAction(action);

                        eventMap.getEventMapElement().add(eventElement);
                    }
                }
            }
        }
    }

    map.setWidgetMap(widgetMap);
    map.setEventMap(eventMap);
    return map;
}

From source file:edu.umd.cs.guitar.ripper.WebRipperMonitor.java

License:Open Source License

@Override
public boolean isExpandable(GComponent component, GWindow window) {
    if (!(component instanceof WebComponent))
        return false;

    WebComponent webCompnent = (WebComponent) component;
    WebElement webElement = webCompnent.getElement();
    if (webElement == null)
        return false;

    if ((!webElement.isDisplayed()) || (!webElement.isEnabled())) {
        GUITARLog.log.debug("Ignore expanding because the element is either not displayed nor enabled ");
        return false;
    }//ww w  .  ja  v a  2  s.  c  o m

    return true;
}

From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.MultiplePatterns.CrawlHandler.java

License:Apache License

/**
 *  handles data behind web form, pagination, ajax based interaction for seed urls
 *///from   ww  w .j  a  v a2  s .  co  m

public void processDriver(WebDriver driver) {
    StringBuffer sBuffer = new StringBuffer();
    String htmlpage = "<html><body>";
    System.out.println("reading url " + driver.getCurrentUrl());
    if (driver.getCurrentUrl().equals("http://www.wikiarms.com/")) {
        // handling pagination

        driver.manage().window().maximize();
        List<WebElement> anchorTags = driver.findElements(By.xpath("//a"));

        for (WebElement anchorTag : anchorTags) {
            htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
            sBuffer.append(anchorTag.getAttribute("href"));
            sBuffer.append("\n");
        }

        WebElement ele = driver.findElement(By.xpath("//*[@id='products-table']/div/ul//a[@rel='next']"));
        for (int i = 0; ele != null; i++) {

            try {
                ele.click();
                System.out.println(driver.getCurrentUrl());
                Thread.sleep(1000);
                List<WebElement> anchorTags2 = driver.findElements(By.xpath("//*[@id='products-table']//a"));

                for (WebElement anchorTag2 : anchorTags2) {
                    htmlpage += "<a href='" + anchorTag2.getAttribute("href") + "'>test</a>";
                    sBuffer.append(anchorTag2.getAttribute("href"));
                    sBuffer.append("\n");
                }
                ele = driver.findElement(By.xpath("//*[@id='products-table']/div/ul//a[@rel='next']"));

            } catch (Exception e) {
                ele = null;

            }

        }
        htmlpage += "</body></html>";
        System.out.println("html is " + htmlpage);
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", htmlpage);
        //return htmlpage;

    } else if (driver.getCurrentUrl().equals("http://www.ksl.com/")) {
        // handling pagination and search guns

        driver.manage().window().maximize();
        WebElement loginWindow = driver
                .findElement(By.xpath("//*[@id='kslHeader']/div/div[1]/div/div[4]/a/span"));
        loginWindow.click();
        WebElement username = driver.findElement(By.className("ksl-header-search__input"));
        username.sendKeys("guns");
        WebElement loginBtn = driver
                .findElement(By.xpath("//*[@id='kslHeader']/div/div[1]/div/div[4]/div/form/button"));
        loginBtn.click();
        System.out.println(driver.getCurrentUrl());
        List pages = driver.findElements(
                By.xpath("//*[@id='___gcse_0']/div/div/div/div[5]/div[2]/div/div/div[2]/div[11]//div"));
        int size = pages.size();
        List<WebElement> anchorTags = driver.findElements(By.xpath("//a"));

        for (WebElement anchorTag : anchorTags) {
            htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
            sBuffer.append(anchorTag.getAttribute("href"));
            sBuffer.append("\n");
        }
        System.out.println(size);
        if (size > 0) {
            for (int i = 2; i < size; i++) {
                System.out.println("inside for loop");
                try {
                    driver.findElement(By.xpath(
                            "//*[@id='___gcse_0']/div/div/div/div[5]/div[2]/div/div/div[2]/div[11]/div/div[" + i
                                    + "]"))
                            .click();
                    Thread.sleep(1000);
                    List<WebElement> anchorTags2 = driver
                            .findElements(By.xpath("/html/body/div[1]/div[2]/div[2]/div[3]/div/div[2]//a"));

                    for (WebElement anchorTag2 : anchorTags2) {
                        htmlpage += "<a href='" + anchorTag2.getAttribute("href") + "'>test</a>";
                        sBuffer.append(anchorTag2.getAttribute("href"));
                        sBuffer.append("\n");
                    }
                } catch (Exception e) {

                }
            }

        }

        htmlpage += "</body></html>";
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", htmlpage);
        System.out.println(htmlpage);

    } else if (driver.getCurrentUrl().equals("http://www.kyclassifieds.com/")) {

        // handling pagination and search guns

        System.out.println("final else loop");
        driver.manage().window().maximize();
        WebElement searchField = driver.findElement(By.xpath("//*[@id='s']"));
        searchField.sendKeys("guns");
        WebElement searchButton = driver.findElement(By.xpath("//*[@id='go']"));
        searchButton.click();
        System.out.println(driver.getCurrentUrl());
        List<WebElement> anchorTags = driver.findElements(By.xpath("//a"));

        for (WebElement anchorTag : anchorTags) {
            htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
            sBuffer.append(anchorTag.getAttribute("href"));
            sBuffer.append("\n");
        }
        WebElement ele = driver.findElement(By.className("next page-numbers"));
        for (int i = 0; ele != null; i++) {

            try {
                ele.click();
                System.out.println(driver.getCurrentUrl());
                Thread.sleep(1000);
                List<WebElement> anchorTags2 = driver
                        .findElements(By.xpath("/html/body/div/div[4]/div/div/div[2]//a"));

                for (WebElement anchorTag2 : anchorTags2) {
                    htmlpage += "<a href='" + anchorTag2.getAttribute("href") + "'>test</a>";
                    sBuffer.append(anchorTag2.getAttribute("href"));
                    sBuffer.append("\n");
                }
                ele = driver.findElement(By.className("next page-numbers"));

            } catch (Exception e) {
                ele = null;

            }

        }
        htmlpage += "</body></html>";
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", htmlpage);
        System.out.println(htmlpage);

    } else if (driver.getCurrentUrl().equals("http://www.iguntrade.com/")) {
        // handling paginations

        List<WebElement> anchorTags = driver.findElements(By.xpath("//a"));

        for (WebElement anchorTag : anchorTags) {
            htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
            sBuffer.append(anchorTag.getAttribute("href"));
            sBuffer.append("\n");
        }
        WebElement ele = driver.findElement(By.className("searchPaginationNext list-last"));
        for (int i = 0; ele != null; i++) {

            try {
                ele.click();
                System.out.println(driver.getCurrentUrl());
                Thread.sleep(1000);
                List<WebElement> anchorTags2 = driver.findElements(By.xpath("//*[@id='main']//a"));

                for (WebElement anchorTag2 : anchorTags2) {
                    htmlpage += "<a href='" + anchorTag2.getAttribute("href") + "'>test</a>";
                    sBuffer.append(anchorTag2.getAttribute("href"));
                    sBuffer.append("\n");
                }
                ele = driver.findElement(By.className("searchPaginationNext list-last"));

            } catch (Exception e) {
                ele = null;

            }

        }
        htmlpage += "</body></html>";
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", htmlpage);
        System.out.println(htmlpage);

    } else if (driver.getCurrentUrl().equals("http://www.gowilkes.com/")) {
        // handling search guns

        WebElement searchField = driver.findElement(By.xpath("//*[@id='search_box']"));
        searchField.sendKeys("guns");
        WebElement classifiedRadioBtn = driver
                .findElement(By.xpath("//*[@id='search_container']/form/div/div[5]/input"));
        classifiedRadioBtn.click();
        WebElement searchButton = driver
                .findElement(By.xpath("//*[@id='search_container']/form/table/tbody/tr/td[2]/span"));
        searchButton.click();
        System.out.println(driver.getCurrentUrl());
        List<WebElement> anchorTags = driver.findElements(By.xpath("//a"));

        for (WebElement anchorTag : anchorTags) {
            htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
            sBuffer.append(anchorTag.getAttribute("href"));
            sBuffer.append("\n");
        }
        List<WebElement> anchorTagGuns = driver
                .findElements(By.xpath("//*[@id='content']/tbody/tr/td[1]/div[2]/table"));
        for (WebElement anchorTag : anchorTagGuns) {
            htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
            sBuffer.append(anchorTag.getAttribute("href"));
            sBuffer.append("\n");
        }
        htmlpage += "</body></html>";
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", htmlpage);
        System.out.println(htmlpage);

    } else if (driver.getCurrentUrl().equals("http://www.floridagunclassifieds.com/")) {
        // handling scrolling of page

        for (int i = 0; i < 20; i++) {
            JavascriptExecutor jse = (JavascriptExecutor) driver;
            jse.executeScript("window.scrollBy(0,250)", "");
        }
        List<WebElement> anchorTags = driver.findElements(By.xpath("//a"));

        for (WebElement anchorTag : anchorTags) {
            htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
            sBuffer.append(anchorTag.getAttribute("href"));
            sBuffer.append("\n");
        }
        htmlpage += "</body></html>";
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", htmlpage);
        System.out.println(htmlpage);
    } else if (driver.getCurrentUrl().equals("http://www.elpasoguntrader.com/")) {
        // handling pagination

        List<WebElement> anchorTags = driver.findElements(By.xpath("//a"));

        for (WebElement anchorTag : anchorTags) {
            htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
            sBuffer.append(anchorTag.getAttribute("href"));
            sBuffer.append("\n");
        }

        WebElement nextField = driver
                .findElement(By.xpath("//*[@id='dj-classifieds']/div/div/div//a[@title='Next']"));
        for (int i = 0; nextField.isEnabled(); i++) {
            try {
                nextField.click();
                Thread.sleep(1000);
                List<WebElement> anchors = driver.findElements(By.xpath("//a"));

                for (WebElement anchorTag : anchors) {
                    htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
                    sBuffer.append(anchorTag.getAttribute("href"));
                    sBuffer.append("\n");
                }
                nextField = driver
                        .findElement(By.xpath("//*[@id='dj-classifieds']/div/div/div//a[@title='Next']"));
            } catch (Exception e) {
            }
        }
        htmlpage += "</body></html>";
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", htmlpage);
        System.out.println(htmlpage);

    } else if (driver.getCurrentUrl().equals("http://www.classifiednc.com/")) {
        // handling gun link tap in left panel and pagination

        WebElement forSale = driver.findElement(By.xpath("//*[@id='body_con']/div[1]/div/div[2]/div[5]"));
        forSale.click();
        WebElement gunList = driver.findElement(By.xpath("//*[@id='catlist']/div[16]/a"));
        gunList.click();
        boolean nextBtn = driver
                .findElement(By.xpath(
                        "//*[@id='classifiedsContainer']/table/tbody/tr/td[2]/table[2]/tbody/tr/td/div/div"))
                .isDisplayed();
        for (int i = 0; nextBtn != false; i++) {
            try {
                Thread.sleep(1000);
                List<WebElement> anchorTags = driver.findElements(
                        By.xpath("//*[@id='classifiedsContainer']/table/tbody/tr/td[2]/table[1]//a"));

                for (WebElement anchorTag : anchorTags) {
                    htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
                    sBuffer.append(anchorTag.getAttribute("href"));
                    sBuffer.append("\n");
                }
                driver.findElement(By.xpath(
                        "//*[@id='classifiedsContainer']/table/tbody/tr/td[2]/table[2]/tbody/tr/td/div/div"))
                        .click();
                nextBtn = driver.findElement(By.xpath(
                        "//*[@id='classifiedsContainer']/table/tbody/tr/td[2]/table[2]/tbody/tr/td/div/div"))
                        .isDisplayed();
            } catch (Exception e) {
            }
        }
        htmlpage += "</body></html>";
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", htmlpage);
        System.out.println(htmlpage);
    } else if (driver.getCurrentUrl().equals("http://www.wantaddigest.com/")) {
        // handling search field
        WebElement forSale = driver.findElement(By.xpath("//*[@id='country']"));
        forSale.sendKeys("guns");
        WebElement nextBtn = driver.findElement(By.xpath("//*[@id='left-home']/form/input[2]"));
        try {
            nextBtn.click();
            Thread.sleep(1000);
            List<WebElement> anchorTags = driver.findElements(By.xpath("//*[@id='middle']//a"));
            for (WebElement anchorTag : anchorTags) {
                htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
                sBuffer.append(anchorTag.getAttribute("href"));
                sBuffer.append("\n");
            }
        } catch (Exception e) {
        }
        htmlpage += "</body></html>";
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", htmlpage);
        System.out.println(htmlpage);

    } else if (driver.getCurrentUrl().equals("http://www.nextechclassifieds.com/")) {
        // handling search field

        WebElement searchField = driver.findElement(By.xpath("//*[@id='nav-search-input']"));
        searchField.sendKeys("guns");
        WebElement searchBtn = driver.findElement(By.xpath("//*[@id='search-btn']"));
        searchBtn.click();
        boolean nextBtn = driver
                .findElement(By.xpath("//*[@id='site-wrapper']/div/div[2]/div/div[2]/ul[1]/li[8]/a"))
                .isEnabled();
        for (int i = 0; nextBtn != false; i++) {
            try {
                Thread.sleep(1000);
                List<WebElement> anchorTags = driver
                        .findElements(By.xpath("//*[@id='gallery-container']/ul//a"));
                for (WebElement anchorTag : anchorTags) {
                    htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
                    sBuffer.append(anchorTag.getAttribute("href"));
                    sBuffer.append("\n");
                }
                driver.findElement(By.xpath("//*[@id='site-wrapper']/div/div[2]/div/div[2]/ul[1]/li[8]/a"))
                        .click();
                nextBtn = driver
                        .findElement(By.xpath("//*[@id='site-wrapper']/div/div[2]/div/div[2]/ul[1]/li[8]/a"))
                        .isEnabled();
            } catch (Exception e) {
            }
        }
        htmlpage += "</body></html>";
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", htmlpage);
        System.out.println(htmlpage);
    } else if (driver.getCurrentUrl().equals("http://www.theoutdoorstrader.com/")) {
        // handling pagination and ajax interaction

        driver.manage().window().maximize();
        WebElement searchField = driver.findElement(By.xpath("//*[@id='QuickSearchQuery']"));
        searchField.click();
        searchField.sendKeys("guns");
        WebElement submitBtn = driver.findElement(By.xpath("//*[@id='QuickSearch']/form/div[2]/dl/dd/input"));
        submitBtn.click();
        List<WebElement> anchorTags = driver.findElements(By.xpath("//*[@id='content']/div/div//a"));
        for (WebElement anchorTag : anchorTags) {
            htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
            sBuffer.append(anchorTag.getAttribute("href"));
            sBuffer.append("\n");
        }

        boolean nextBtn = driver.findElement(By.linkText("Next >")).isDisplayed();

        for (int i = 0; nextBtn != false; i++) {
            try {
                Thread.sleep(1000);
                driver.findElement(By.linkText("Next >")).click();
                List<WebElement> anchors = driver.findElements(By.xpath("//*[@id='content']/div/div//a"));
                for (WebElement anchorTag : anchors) {
                    htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
                    sBuffer.append(anchorTag.getAttribute("href"));
                    sBuffer.append("\n");
                }
                nextBtn = driver.findElement(By.linkText("Next >")).isDisplayed();
            } catch (Exception e) {
                nextBtn = false;
            }
        }

        htmlpage += "</body></html>";
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("document.body.innerHTML=arguments[0]", htmlpage);
        System.out.println(htmlpage);
    } else if (driver.getCurrentUrl().equals("http://www.arguntrader.com/")) {
        // handling web form data

        driver.manage().window().maximize();
        WebElement searchField = driver
                .findElement(By.xpath("//*[@id='page-header']/div[2]/div/ul[2]/li[3]/a"));
        searchField.click();
        WebElement usernameField = driver.findElement(By.xpath("//*[@id='username']"));
        usernameField.sendKeys("testing");
        WebElement passwordField = driver.findElement(By.xpath("//*[@id='password']"));
        passwordField.sendKeys("usccsci572");
        WebElement loginBtn = driver
                .findElement(By.xpath("//*[@id='login']/div[1]/div/div/fieldset/dl[4]/dd/input[3]"));
        loginBtn.click();
        try {
            Thread.sleep(5000);
            List<WebElement> anchorTags = driver.findElements(By.xpath("//a"));

            for (WebElement anchorTag : anchorTags) {
                htmlpage += "<a href='" + anchorTag.getAttribute("href") + "'>test</a>";
                sBuffer.append(anchorTag.getAttribute("href"));
                sBuffer.append("\n");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        System.out.println("else loop");
    }
    writeURLToFile(sBuffer);
}

From source file:io.fabric8.selenium.FormFacade.java

License:Apache License

public void submit() {
    getFacade().until("Form inputs: " + inputValues, new ExpectedCondition<Boolean>() {
        @Override//from  w w  w. ja  va 2  s . c  o m
        public Boolean apply(WebDriver driver) {
            logWait("" + inputValues + " on " + driver.getCurrentUrl());
            WebElement submitElement = null;
            for (InputValue inputValue : inputValues) {
                submitElement = inputValue.doInput();
                if (submitElement == null) {
                    logInfo("Missing " + inputValue + "");
                    return false;
                }
            }
            if (submitBy == null && submitElement == null) {
                fail("No input fields submitted yet");
                return false;
            } else {
                getFacade().sleep(Millis.seconds(5));
                if (submitBy != null) {
                    getFacade().untilIsEnabled(submitBy);
                    submitElement = getFacade().findOptionalElement(submitBy);
                    if (submitElement == null) {
                        logWarn("Could not find submit button " + submitBy + "");
                        return false;
                    } else {
                        if (!submitElement.isDisplayed() || !submitElement.isEnabled()) {
                            logWarn("Submit button " + submitBy + " not enabled and visible");
                            return false;
                        }
                        logInfo("Submitting form: " + inputValues + " on " + submitElement + "");
                        submitElement.click();
                    }
                } else {
                    logInfo("Submitting form: " + inputValues + " on " + submitElement + "");
                    submitElement.submit();
                }
                return true;
            }
        }
    });
}

From source file:io.fabric8.selenium.WebDriverFacade.java

License:Apache License

public boolean untilSelectedByVisibleText(long timeoutInSeconds, final By by, final String value) {
    String message = "select " + by + " with value: " + value;
    return new WebDriverWait(getDriver(), timeoutInSeconds).withMessage(message)
            .until(new ExpectedCondition<Boolean>() {
                @Override//  ww w  .  ja  v  a2  s .  c  o  m
                public Boolean apply(WebDriver webDriver) {
                    WebElement element = findOptionalElement(by);
                    if (element != null && element.isEnabled()) {
                        Select select = new Select(element);
                        try {
                            select.selectByVisibleText(value);
                            logInfo("" + by + " select " + select + " selected value: " + value);
                            return true;
                        } catch (NoSuchElementException e) {
                            logWait("" + by + " select " + select + " does not yet have value: " + value);
                            return false;
                        }
                    } else {
                        logWait("" + by + " not enabled");
                        return false;
                    }
                }
            });
}

From source file:io.fabric8.selenium.WebDriverFacade.java

License:Apache License

public boolean untilIsEnabled(long timeoutInSeconds, final By by) {
    return untilElementPredicate(timeoutInSeconds, by, new Function<WebElement, Boolean>() {
        @Override/*from   w ww .  j  ava  2  s  . c o m*/
        public String toString() {
            return "element.isEnabled()";
        }

        @Override
        public Boolean apply(WebElement element) {
            return element.isEnabled();
        }
    });
}

From source file:io.fabric8.selenium.WebDriverFacade.java

License:Apache License

/**
 * Waits until one of the given elements is available
 *///from   ww w . j a v a2  s  .com
public void untilOneOf(final By... bys) {
    final List<By> byList = Arrays.asList(bys);
    String message = "One of these is available: " + byList;
    until(message, defaultTimeoutInSeconds, new ExpectedCondition<Boolean>() {

        @Override
        public Boolean apply(WebDriver driver) {
            for (By by : bys) {
                WebElement element = findOptionalElement(by);
                if (element != null && element.isDisplayed() && element.isEnabled()) {
                    logInfo("Found " + element + " for " + by + "");
                    return true;
                }
            }
            logInfo("Still not found any of " + byList + "");
            return false;
        }
    });
}

From source file:io.github.seleniumquery.by.css.pseudoclasses.DisabledPseudoClass.java

License:Apache License

@Override
public boolean isPseudoClass(WebDriver driver, WebElement element, PseudoClassSelector pseudoClassSelector) {
    // #Cross-Driver
    // When there is a not disabled <option> under a disabled <optgroup>, HtmlUnitDriver considers
    // the <option> to be enabled, when it is not
    if (DriverVersionUtils.getInstance().isHtmlUnitDriver(driver) && OPTION.equals(element.getTagName())) {
        WebElement optionParent = SelectorUtils.parent(element);
        if (OPTGROUP.equals(optionParent.getTagName()) && !optionParent.isEnabled()) {
            return true;
        }/*w  ww . j av a 2s  .c om*/
    }
    return !element.isEnabled() && DISABLEABLE_TAGS.contains(element.getTagName());
}

From source file:io.github.seleniumquery.by.css.pseudoclasses.EnabledPseudoClass.java

License:Apache License

@Override
public boolean isPseudoClass(WebDriver driver, WebElement element, PseudoClassSelector pseudoClassSelector) {
    // #Cross-Driver
    // When there is a not disabled <option> under a disabled <optgroup>, HtmlUnitDriver considers
    // the <option> to be enabled, when it is not
    if (DriverVersionUtils.getInstance().isHtmlUnitDriver(driver) && OPTION_TAG.equals(element.getTagName())) {
        WebElement optionParent = SelectorUtils.parent(element);
        if (OPTGROUP_TAG.equals(optionParent.getTagName()) && !optionParent.isEnabled()) {
            return false;
        }//from   w  w w .  j  a v a 2s . c o  m
    }
    return element.isEnabled() && ENABLEABLE_TAGS.contains(element.getTagName());
}