Search in sources :

Example 91 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project vividus by vividus-framework.

the class ExpectedSearchActionsConditionsTests method testTextToBePresentInElementLocatedNoElements.

@Test
void testTextToBePresentInElementLocatedNoElements() {
    when(locator.toString()).thenReturn(TEXT);
    mockFindElements();
    IExpectedSearchContextCondition<Boolean> condition = expectedSearchActionsConditions.textToBePresentInElementLocated(locator, TEXT);
    NoSuchElementException exception = assertThrows(NoSuchElementException.class, () -> condition.apply(searchContext));
    assertThat(exception.getMessage(), containsString(NO_SUCH_ELEMENT));
}
Also used : NoSuchElementException(org.openqa.selenium.NoSuchElementException) Test(org.junit.jupiter.api.Test)

Example 92 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project htmlunit by HtmlUnit.

the class HtmlPage3Test method shouldBeAbleToFindElementByXPathInXmlDocument.

/**
 * @throws Exception if an error occurs
 */
@Test
@Alerts(DEFAULT = "error", CHROME = "Something", EDGE = "Something")
@NotYetImplemented({ IE, FF, FF_ESR })
public void shouldBeAbleToFindElementByXPathInXmlDocument() throws Exception {
    final String html = "<?xml version='1.0' encoding='UTF-8'?>\n" + "<html xmlns='http://www.w3.org/1999/xhtml'\n" + "      xmlns:svg='http://www.w3.org/2000/svg'\n" + "      xmlns:xlink='http://www.w3.org/1999/xlink'>\n" + "<body>\n" + "  <svg:svg id='chart_container' height='220' width='400'>\n" + "    <svg:text y='16' x='200' text-anchor='middle'>Something</svg:text>\n" + "  </svg:svg>\n" + "</body>\n" + "</html>\n";
    final WebDriver driver = loadPage2(html, URL_FIRST, "application/xhtml+xml", ISO_8859_1, null);
    String actual;
    try {
        final WebElement element = driver.findElement(By.xpath("//svg:svg//svg:text"));
        actual = element.getText();
    } catch (final NoSuchElementException e) {
        actual = "error";
    }
    assertEquals(getExpectedAlerts()[0], actual);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) NotYetImplemented(com.gargoylesoftware.htmlunit.junit.BrowserRunner.NotYetImplemented) Test(org.junit.Test) Alerts(com.gargoylesoftware.htmlunit.junit.BrowserRunner.Alerts)

Example 93 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project selenium_java by sergueik.

the class NgLocalFileIntegrationTest method testHover.

// @Ignore
@Test
public void testHover() {
    getPageContent("ng_hover1.htm");
    // Hover over menu
    WebElement element = seleniumDriver.findElement(By.id("hover"));
    highlight(element);
    actions.moveToElement(element).build().perform();
    // Wait for the Angular 'hovering' property to get evaluated to true
    WebDriverWait wait2 = new WebDriverWait(seleniumDriver, 120);
    wait2.pollingEvery(Duration.ofMillis(pollingInterval));
    wait2.until(new ExpectedCondition<Boolean>() {

        // NOTE: 'until' only prints "hovering: true" and never "hovering: false"
        @Override
        public Boolean apply(WebDriver d) {
            NgWebDriver ngD = new NgWebDriver(d);
            // org.openqa.selenium.WebDriverException: The WebDriver instance must
            // implement JavaScriptExecutor interface.
            NgWebElement ng_element = ngD.findElement(By.id("hover"));
            Object value = ng_element.evaluate("hovering");
            System.err.println("hovering: " + value.toString());
            return Boolean.parseBoolean(value.toString());
        }
    });
    actions.moveByOffset(0, 300).build().perform();
    // Wait for the tooltip div to get visible
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    actions.moveToElement(element).build().perform();
    try {
        wait.until(ExpectedConditions.visibilityOf(seleniumDriver.findElement(By.cssSelector("div[ng-show='hovering']"))));
    } catch (NoSuchElementException e) {
    }
}
Also used : WebDriver(org.openqa.selenium.WebDriver) NgWebDriver(com.github.sergueik.jprotractor.NgWebDriver) NgWebDriver(com.github.sergueik.jprotractor.NgWebDriver) WebDriverWait(org.openqa.selenium.support.ui.WebDriverWait) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) Test(org.junit.Test)

Example 94 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project selenium_java by sergueik.

the class NgLocalFileIntegrationTest method testDropDownWatch.

// @Ignore
@Test
public void testDropDownWatch() {
    // NOTE: works with Angular 1.2.13, fails withAngular 1.4.9
    getPageContent("ng_dropdown_watch.htm");
    String optionsCountry = "country for country in countries";
    List<WebElement> elementsCountries = ngDriver.findElements(NgBy.options(optionsCountry));
    assertThat(elementsCountries.size(), equalTo(3));
    for (WebElement country : elementsCountries) {
        if (country.getAttribute("value").isEmpty()) {
            continue;
        }
        assertTrue(country.getAttribute("value").matches("^\\d+$"));
        assertTrue(country.getText().matches("(?i:China|United States)"));
        System.err.println("country = " + country.getText() + ", value: " + country.getAttribute("value"));
    }
    String optionsState = "state for state in states";
    WebElement elementState = ngDriver.findElement(NgBy.options(optionsState));
    assertFalse(elementState.isEnabled());
    Select selectCountries = new Select(ngDriver.findElement(NgBy.model("country")));
    selectCountries.selectByVisibleText("china");
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    WebElement selectedOptionCountry = ngDriver.findElement(NgBy.selectedOption(optionsCountry));
    try {
        assertThat(selectedOptionCountry, notNullValue());
        assertThat(selectedOptionCountry.getText(), equalTo("china"));
    } catch (NullPointerException e) {
    }
    assertTrue(elementState.isEnabled());
    List<WebElement> elementsStates = ngDriver.findElements(NgBy.options(optionsState));
    assertThat(elementsStates.size(), equalTo(3));
    for (WebElement state : elementsStates) {
        if (state.getAttribute("value").isEmpty()) {
            continue;
        }
        assertTrue(state.getAttribute("value").matches("^\\d+$"));
        assertTrue(state.getText().matches("(?i:BeiJing|ShangHai)"));
        System.err.println("state = " + state.getText());
    }
    Select selectStates = new Select(ngDriver.findElement(NgBy.model("state")));
    for (WebElement option : selectStates.getOptions()) {
        if (option.getText().isEmpty()) {
            break;
        }
        System.err.println("option: '" + option.getText() + "', value : " + option.getAttribute("value"));
        if (option.getText().equalsIgnoreCase("ShangHai")) {
            option.click();
        }
    }
    try {
        // TODO: fails:
        selectCountries.selectByVisibleText("ShangHai");
    } catch (NoSuchElementException e) {
    }
    List<WebElement> cities = ngDriver.findElements(NgBy.options("city for city in cities"));
    for (WebElement option : cities) {
        if (option.getText().isEmpty()) {
            break;
        }
        System.err.println("option: '" + option.getText() + "', value : " + option.getAttribute("value"));
    }
    if (!isCIBuild) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
        }
    }
}
Also used : Select(org.openqa.selenium.support.ui.Select) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) Test(org.junit.Test)

Example 95 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project selenium_java by sergueik.

the class NgSvgIntegrationTest method testCircles.

@Test
public void testCircles() {
    // if (isCIBuild) { // Alert not handled by PhantomJS
    // return;
    // }
    getPageContent("ng_svg_ex1.htm");
    for (WebElement circle : ngDriver.findElements(NgBy.repeater("circle in circles"))) {
        // if (circle.getText().isEmpty()){
        // break;
        // }
        Object x = new NgWebElement(ngDriver, circle).evaluate("circle.x");
        Object y = new NgWebElement(ngDriver, circle).evaluate("circle.y");
        Object r = new NgWebElement(ngDriver, circle).evaluate("circle.r");
        highlight(circle);
        formatter.format("x = %1$2d y = %2$2d r = %3$2d\n", x, y, r);
        formatter.format("Location: x = %3d", circle.getLocation().x);
        formatter.format(" y = %3d", circle.getLocation().y);
        System.err.println(sb.toString());
        sb.setLength(0);
        try {
            WebElement element = seleniumDriver.findElement(By.xpath(xpath_of(circle)));
            System.err.println("Located by xpath " + xpath_of(circle));
            formatter.format("Location: x = %3d", element.getLocation().x);
            formatter.format(" y = %3d", element.getLocation().y);
            System.err.println(sb.toString());
            sb.setLength(0);
            highlight(element);
        } catch (NoSuchElementException ex) {
            // at <anonymous class>.FirefoxDriver.prototype.findElementInternal_
            System.err.println("Cannot locate by xpath: " + xpath_of(circle));
        }
        try {
            WebElement element = seleniumDriver.findElement(By.cssSelector(css_selector_of(circle)));
            System.err.println("Located by cssSelector " + css_selector_of(circle));
            highlight(element);
            System.err.println("innerHTML:" + element.getAttribute("innerHTML"));
            // WebDriverException: cannot forward the request Software caused
            // connection abort
            System.err.println("Fill: " + CommonFunctions.executeScript("return arguments[0].getAttribute('fill')", element));
        } catch (NoSuchElementException ex) {
            System.err.println("Cannot locate by cssSelector: " + css_selector_of(circle));
        }
    }
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
}
Also used : NgWebElement(com.github.sergueik.jprotractor.NgWebElement) NgWebElement(com.github.sergueik.jprotractor.NgWebElement) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) Test(org.junit.Test)

Aggregations

NoSuchElementException (org.openqa.selenium.NoSuchElementException)388 WebElement (org.openqa.selenium.WebElement)210 Test (org.junit.Test)61 TimeoutException (org.openqa.selenium.TimeoutException)52 Test (org.testng.annotations.Test)50 WebDriverException (org.openqa.selenium.WebDriverException)38 MessageEvent (org.cerberus.engine.entity.MessageEvent)34 WebDriver (org.openqa.selenium.WebDriver)30 Test (org.junit.jupiter.api.Test)29 WebDriverWait (org.openqa.selenium.support.ui.WebDriverWait)29 MockitoTest (com.seleniumtests.MockitoTest)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)23 Select (org.openqa.selenium.support.ui.Select)22 By (org.openqa.selenium.By)20 AnswerItem (org.cerberus.util.answer.AnswerItem)18 WebElementLocator (de.learnlib.alex.data.entities.WebElementLocator)16 StaleElementReferenceException (org.openqa.selenium.StaleElementReferenceException)14 Actions (org.openqa.selenium.interactions.Actions)14 ArrayList (java.util.ArrayList)13 CerberusEventException (org.cerberus.exception.CerberusEventException)11