Search in sources :

Example 1 with StaleElementReferenceException

use of org.openqa.selenium.StaleElementReferenceException in project sonarqube by SonarSource.

the class Retry method execute.

<T> void execute(Supplier<Optional<T>> target, Consumer<T> action) {
    WebDriverException lastError = null;
    boolean retried = false;
    long start = System.currentTimeMillis();
    while ((System.currentTimeMillis() - start) < timeoutInMs) {
        try {
            Optional<T> targetElement = target.get();
            if (targetElement.isPresent()) {
                action.accept(targetElement.get());
                if (retried) {
                    System.out.println();
                }
                return;
            }
        } catch (StaleElementReferenceException e) {
        // ignore
        } catch (WebDriverException e) {
            lastError = e;
        }
        retried = true;
        System.out.print(".");
    }
    if (retried) {
        System.out.println();
    }
    if (lastError != null) {
        throw lastError;
    }
    throw new NoSuchElementException("Not found");
}
Also used : StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) NoSuchElementException(java.util.NoSuchElementException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 2 with StaleElementReferenceException

use of org.openqa.selenium.StaleElementReferenceException in project opennms by OpenNMS.

the class JmxConfigurationGeneratorIT method configureJMXConnection.

protected void configureJMXConnection(final boolean skipDefaultVM) throws Exception {
    final long end = System.currentTimeMillis() + LOAD_TIMEOUT;
    final WebDriverWait shortWait = new WebDriverWait(m_driver, 10);
    final String skipDefaultVMxpath = "//span[@id='skipDefaultVM']/input";
    final boolean selected = waitForElement(By.xpath(skipDefaultVMxpath)).isSelected();
    LOG.debug("skipDefaultVM selected: {}", selected);
    if (selected != skipDefaultVM) {
        waitForElement(By.xpath(skipDefaultVMxpath)).click();
    }
    // configure authentication
    final WebElement authenticateElement = waitForElement(By.id("authenticate"));
    if (!authenticateElement.isSelected()) {
        authenticateElement.findElement(By.tagName("input")).click();
    }
    /*
         * Sometimes, Vaadin just loses input, or focus.  Or both!  I suspect it's
         * because of the way Vaadin handles events and DOM-redraws itself, but...
         * ¯\_(ツ)_/¯
         *
         * To make sure it really really *really* works, there are multiple layers
         * of belt-and-suspenders-and-glue-and-staples:
         *
         * 1. Click first to ensure the field is focused
         * 2. Clear the current contents of the field
         * 3. Send the text to the field
         * 4. Click it *again* because sometimes this wakes up the event handler
         * 5. Do it all in a loop that checks for validation errors, because
         *    *sometimes* even with all that, it will fail to fill in a field...
         *    In that case, hit escape to clear the error message and start all
         *    over and try again.
         */
    boolean found = false;
    do {
        setVaadinValue("authenticateUser", "admin");
        setVaadinValue("authenticatePassword", "admin");
        // go to next page
        waitForElement(By.id("next")).click();
        try {
            setImplicitWait(1, TimeUnit.SECONDS);
            found = shortWait.until(new ExpectedCondition<Boolean>() {

                @Override
                public Boolean apply(final WebDriver driver) {
                    try {
                        final WebElement elem = driver.findElement(By.cssSelector("div.v-Notification-error h1"));
                        LOG.debug("Notification error element: {}", elem);
                        if (elem != null) {
                            elem.sendKeys(Keys.ESCAPE);
                            return false;
                        }
                    } catch (final NoSuchElementException | StaleElementReferenceException e) {
                        LOG.warn("Exception while checking for errors message.", e);
                    }
                    try {
                        final Boolean contains = pageContainsText(MBEANS_VIEW_TREE_WAIT_NAME).apply(driver);
                        LOG.debug("Page contains '{}'? {}", MBEANS_VIEW_TREE_WAIT_NAME, contains);
                        return contains;
                    } catch (final Exception e) {
                        LOG.warn("Exception while checking for next page.", e);
                    }
                    return false;
                }
            });
        } catch (final Exception e) {
            LOG.debug("Failed to configure authentication and port.", e);
        } finally {
            setImplicitWait();
        }
    } while (System.currentTimeMillis() < end && !found);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) ExpectedCondition(org.openqa.selenium.support.ui.ExpectedCondition) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 3 with StaleElementReferenceException

use of org.openqa.selenium.StaleElementReferenceException in project geode by apache.

the class PulseTestUtils method clickElementUsingId.

public static void clickElementUsingId(String id) {
    WebDriverException lastException = null;
    int attempts = 3;
    while (attempts > 0) {
        try {
            waitForElementWithId(id).click();
            return;
        } catch (StaleElementReferenceException sere) {
            lastException = sere;
        }
        attempts++;
    }
    throw lastException;
}
Also used : StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) WebDriverException(org.openqa.selenium.WebDriverException)

Example 4 with StaleElementReferenceException

use of org.openqa.selenium.StaleElementReferenceException in project zeppelin by apache.

the class ZeppelinIT method testSparkInterpreterDependencyLoading.

@Test
public void testSparkInterpreterDependencyLoading() throws Exception {
    if (!endToEndTestEnabled()) {
        return;
    }
    try {
        // navigate to interpreter page
        WebElement settingButton = driver.findElement(By.xpath("//button[@class='nav-btn dropdown-toggle ng-scope']"));
        settingButton.click();
        WebElement interpreterLink = driver.findElement(By.xpath("//a[@href='#/interpreter']"));
        interpreterLink.click();
        // add new dependency to spark interpreter
        driver.findElement(By.xpath("//div[@id='spark']//button[contains(.,'edit')]")).sendKeys(Keys.ENTER);
        WebElement depArtifact = pollingWait(By.xpath("//input[@ng-model='setting.depArtifact']"), MAX_BROWSER_TIMEOUT_SEC);
        String artifact = "org.apache.commons:commons-csv:1.1";
        depArtifact.sendKeys(artifact);
        driver.findElement(By.xpath("//div[@id='spark']//form//button[1]")).click();
        clickAndWait(By.xpath("//div[@class='modal-dialog'][contains(.,'Do you want to update this interpreter and restart with new settings?')]" + "//div[@class='modal-footer']//button[contains(.,'OK')]"));
        try {
            clickAndWait(By.xpath("//div[@class='modal-dialog'][contains(.,'Do you want to " + "update this interpreter and restart with new settings?')]//" + "div[@class='bootstrap-dialog-close-button']/button"));
        } catch (TimeoutException | StaleElementReferenceException e) {
        //Modal dialog got closed earlier than expected nothing to worry.
        }
        driver.navigate().back();
        createNewNote();
        // wait for first paragraph's " READY " status text
        waitForParagraph(1, "READY");
        setTextOfParagraph(1, "import org.apache.commons.csv.CSVFormat");
        runParagraph(1);
        waitForParagraph(1, "FINISHED");
        // check expected text
        WebElement paragraph1Result = driver.findElement(By.xpath(getParagraphXPath(1) + "//div[contains(@id,\"_text\")]"));
        collector.checkThat("Paragraph from ZeppelinIT of testSparkInterpreterDependencyLoading result: ", paragraph1Result.getText().toString(), CoreMatchers.containsString("import org.apache.commons.csv.CSVFormat"));
        //delete created notebook for cleanup.
        deleteTestNotebook(driver);
        ZeppelinITUtils.sleep(1000, false);
        // reset dependency
        settingButton.click();
        interpreterLink.click();
        driver.findElement(By.xpath("//div[@id='spark']//button[contains(.,'edit')]")).sendKeys(Keys.ENTER);
        WebElement testDepRemoveBtn = pollingWait(By.xpath("//tr[descendant::text()[contains(.,'" + artifact + "')]]/td[3]/button"), MAX_IMPLICIT_WAIT);
        testDepRemoveBtn.sendKeys(Keys.ENTER);
        driver.findElement(By.xpath("//div[@id='spark']//form//button[1]")).click();
        driver.findElement(By.xpath("//div[@class='modal-dialog'][contains(.,'Do you want to update this interpreter and restart with new settings?')]" + "//div[@class='modal-footer']//button[contains(.,'OK')]")).click();
    } catch (Exception e) {
        handleException("Exception in ZeppelinIT while testSparkInterpreterDependencyLoading ", e);
    }
}
Also used : StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) WebElement(org.openqa.selenium.WebElement) StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) TimeoutException(org.openqa.selenium.TimeoutException) TimeoutException(org.openqa.selenium.TimeoutException) Test(org.junit.Test)

Example 5 with StaleElementReferenceException

use of org.openqa.selenium.StaleElementReferenceException in project sonarqube by SonarSource.

the class Retry method execute.

<T> void execute(Runnable action) {
    WebDriverException lastError = null;
    boolean retried = false;
    long start = System.currentTimeMillis();
    while ((System.currentTimeMillis() - start) < timeoutInMs) {
        try {
            action.run();
            if (retried) {
                System.out.println();
            }
            return;
        } catch (StaleElementReferenceException e) {
        // ignore
        } catch (WebDriverException e) {
            lastError = e;
        }
        retried = true;
        System.out.print(".");
    }
    if (retried) {
        System.out.println();
    }
    if (lastError != null) {
        throw lastError;
    }
    throw new NoSuchElementException("Not found");
}
Also used : StaleElementReferenceException(org.openqa.selenium.StaleElementReferenceException) NoSuchElementException(java.util.NoSuchElementException) WebDriverException(org.openqa.selenium.WebDriverException)

Aggregations

StaleElementReferenceException (org.openqa.selenium.StaleElementReferenceException)5 WebDriverException (org.openqa.selenium.WebDriverException)3 NoSuchElementException (java.util.NoSuchElementException)2 WebElement (org.openqa.selenium.WebElement)2 Test (org.junit.Test)1 NoSuchElementException (org.openqa.selenium.NoSuchElementException)1 TimeoutException (org.openqa.selenium.TimeoutException)1 WebDriver (org.openqa.selenium.WebDriver)1 ExpectedCondition (org.openqa.selenium.support.ui.ExpectedCondition)1 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)1