Search in sources :

Example 51 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project uaa by cloudfoundry.

the class SamlLoginWithLocalIdpIT method performLogin.

public void performLogin(String idpZoneId, String idpZoneUserEmail, String idpZoneUrl, IdentityZone spZone, String spZoneUrl, SamlIdentityProviderDefinition samlIdentityProviderDefinition) {
    webDriver.get(baseUrl + "/logout.do");
    webDriver.get(spZoneUrl + "/logout.do");
    webDriver.get(idpZoneUrl + "/logout.do");
    webDriver.get(spZoneUrl + "/");
    assertEquals(spZone.getName(), webDriver.getTitle());
    Cookie beforeLogin = webDriver.manage().getCookieNamed("JSESSIONID");
    assertNotNull(beforeLogin);
    assertNotNull(beforeLogin.getValue());
    List<WebElement> elements = webDriver.findElements(By.xpath("//a[text()='" + samlIdentityProviderDefinition.getLinkText() + "']"));
    assertNotNull(elements);
    assertEquals(1, elements.size());
    WebElement element = elements.get(0);
    assertNotNull(element);
    element.click();
    try {
        webDriver.findElement(By.xpath("//h1[contains(text(), 'Welcome to The Twiglet Zone[" + idpZoneId + "]!')]"));
        webDriver.findElement(By.name("username")).clear();
        webDriver.findElement(By.name("username")).sendKeys(idpZoneUserEmail);
        webDriver.findElement(By.name("password")).sendKeys("secr3T");
        webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();
        assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), containsString("Where to?"));
        Cookie afterLogin = webDriver.manage().getCookieNamed("JSESSIONID");
        assertNotNull(afterLogin);
        assertNotNull(afterLogin.getValue());
        assertNotEquals(beforeLogin.getValue(), afterLogin.getValue());
    } catch (Exception e) {
        assertTrue("Http-Artifact binding is not supported", e instanceof NoSuchElementException);
    }
}
Also used : Cookie(org.openqa.selenium.Cookie) WebElement(org.openqa.selenium.WebElement) UnknownHostException(java.net.UnknownHostException) NoSuchElementException(org.openqa.selenium.NoSuchElementException) HttpClientErrorException(org.springframework.web.client.HttpClientErrorException) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 52 with NoSuchElementException

use of org.openqa.selenium.NoSuchElementException in project uaa by cloudfoundry.

the class LdapLoginIT method saveAlertErrorMessage.

private void saveAlertErrorMessage() {
    try {
        WebElement element = webDriver.findElement(By.className("alert-error"));
        alertError = Optional.of(element.getText());
    } catch (NoSuchElementException e) {
    // do nothing
    }
}
Also used : WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException)

Example 53 with NoSuchElementException

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

the class YandexTest method doLogin.

private String doLogin() {
    // I enter the username
    // NOTE: elements with class names ending with "Label" e.g.
    // "passport-Input-Label"
    // would not accept input
    WebElement element = driver.findElement(By.xpath("//form//input[@name='login']"));
    System.err.println("Form element containing login: " + element.findElement(By.xpath("..")).findElement(By.xpath("..")).getAttribute("outerHTML"));
    highlight(element);
    element.clear();
    element.sendKeys(username);
    element = driver.findElement(By.cssSelector("input[name='passwd']"));
    highlight(element);
    element.clear();
    element.sendKeys(password);
    // TODO: Assert that input gets added to the background form
    System.err.println("Password: " + element.getAttribute("value"));
    // Evaluate the landing page URL
    // element = driver
    // .findElement(By.cssSelector("form.new-auth-form input[name='passwd']"));
    element = driver.findElement(By.cssSelector("form button[type='submit']"));
    highlight(element);
    element = driver.findElement(By.cssSelector("form a.nb-button"));
    String login_href = element.getAttribute("href");
    System.err.println("Login href: " + login_href);
    String matcherExpression = String.format("%s/auth\\?(?:.*)&retpath=(.+)&(?:.*)", loginURL);
    System.err.println("Matcher: " + matcherExpression);
    Pattern pattern = Pattern.compile(matcherExpression);
    Matcher matcher = pattern.matcher(login_href);
    String retpath = null;
    if (matcher.find()) {
        try {
            retpath = java.net.URLDecoder.decode(matcher.group(1).toString(), "UTF-8");
        } catch (UnsupportedEncodingException e) {
        // ignore
        }
    }
    System.err.println("Login retpath: " + retpath);
    // And I click the login button
    element = driver.findElement(By.cssSelector("form button[type='submit']"));
    highlight(element);
    // String currentUrl = driver.getCurrentUrl();
    element.click();
    // wait until browser is away from the login page
    System.err.println("Waiting to get away from " + loginURL);
    try {
        wait.until(ExpectedConditions.not(ExpectedConditions.urlContains(loginURL)));
    } catch (TimeoutException tex) {
        try {
            element = driver.findElement(By.cssSelector("div.layout-inner div.js-messages div.error-msg"));
            String errorMessageTranslated = Translit.toAscii(element.getText());
            verificationErrors.append("Getting error message " + errorMessageTranslated);
            System.err.println("Getting error message " + errorMessageTranslated);
        } catch (NoSuchElementException elex) {
        // ignore
        }
        verificationErrors.append(tex.toString());
    }
    System.err.println("Waiting for " + retpath);
    // wait until browser is on the landing page
    wait.until(ExpectedConditions.urlContains(retpath));
    // System.out.println("Page url: " + driver.getCurrentUrl());
    try {
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.mail-App-Header div.mail-User")));
    } catch (TimeoutException | UnreachableBrowserException e) {
        verificationErrors.append(e.toString());
    }
    return retpath;
}
Also used : Pattern(java.util.regex.Pattern) Matcher(java.util.regex.Matcher) UnreachableBrowserException(org.openqa.selenium.remote.UnreachableBrowserException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) TimeoutException(org.openqa.selenium.TimeoutException)

Example 54 with NoSuchElementException

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

the class GeoPlacesDropdownTest method testDropdownSelect.

@Test(enabled = true)
public void testDropdownSelect() {
    // Arrange
    // work with the address input
    element = iframeDriver.findElement(By.id("pac-input"));
    assertThat(element, notNullValue());
    // Act
    element.sendKeys(searchText);
    sleep(1000);
    // scroll few items down through the search results menu
    actions = new Actions(iframeDriver);
    for (int cnt = 0; cnt != 10; cnt++) {
        actions.sendKeys(Keys.ARROW_DOWN).perform();
        sleep(500);
    }
    // the dynamic div is visible in Firefox, not in Chrome or Vivaldi -
    // Shadow DOM present ?
    /*
		<div class="pac-container pac-logo hdpi" style="width: 398px; position: absolute; left: 17px; top: 39px; display: none;">
		  <div class="pac-item">
		    <span class="pac-icon pac-icon-marker"/>
		    <span class="pac-item-query">
		      <span class="pac-matched">Miami Airport</span>
		    </span>
		    <span><span class="pac-matched">Mia</span>mi, FL, USA</span>
		  </div>
		  <div class="pac-item">
		    <span class="pac-icon pac-icon-marker"/>
		    <span class="pac-item-query">
		      <span class="pac-matched">Miami International Airport (MIA)</span>
		    </span>
		    <span>Northwest 42nd Avenue, Miami, <span class="pac-matched">Mia</span>mi-Dade, FL, USA</span>
		  </div>
		</div>
		*/
    // Assert
    elements = iframeDriver.findElements(By.className("pac-item"));
    assertThat(elements, notNullValue());
    iteratorElements = elements.iterator();
    cnt = 0;
    while (iteratorElements.hasNext()) {
        cnt++;
        element = iteratorElements.next();
        // System.err.println(element.getAttribute("outerHTML"));
        text = null;
        try {
            text = element.getText();
            assertThat(text, notNullValue());
            System.err.println(String.format("geocode search result %2d: %s", cnt, text));
        } catch (NoSuchElementException e) {
            System.err.println("Exception (ignored): " + e.getMessage());
        }
    }
    // count results added to the page
    assertThat(cnt, not(greaterThan(maxItems)));
}
Also used : Actions(org.openqa.selenium.interactions.Actions) NoSuchElementException(org.openqa.selenium.NoSuchElementException) Test(org.testng.annotations.Test)

Example 55 with NoSuchElementException

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

the class MultilineLocalizedPageSearchTest method failedReciprocalMultilineTextSearchTest.

@Test(enabled = false)
public void failedReciprocalMultilineTextSearchTest() {
    List<WebElement> elements = driver.findElements(By.cssSelector(elementCssSelector));
    String elementText = elements.get(0).getText();
    try {
        WebElement element = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath(String.format(complexXPathTemplate, elementText)))));
        if (element != null) {
            highlight(element);
        }
    } catch (NoSuchElementException e) {
        System.err.println("Exception (ignored): " + e.toString());
    }
}
Also used : WebElement(org.openqa.selenium.WebElement) RemoteWebElement(org.openqa.selenium.remote.RemoteWebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) Test(org.testng.annotations.Test)

Aggregations

NoSuchElementException (org.openqa.selenium.NoSuchElementException)393 WebElement (org.openqa.selenium.WebElement)212 Test (org.junit.Test)63 TimeoutException (org.openqa.selenium.TimeoutException)53 Test (org.testng.annotations.Test)50 WebDriverException (org.openqa.selenium.WebDriverException)39 MessageEvent (org.cerberus.engine.entity.MessageEvent)35 Test (org.junit.jupiter.api.Test)29 WebDriver (org.openqa.selenium.WebDriver)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)21 AnswerItem (org.cerberus.util.answer.AnswerItem)18 WebElementLocator (de.learnlib.alex.data.entities.WebElementLocator)16 ArrayList (java.util.ArrayList)13 StaleElementReferenceException (org.openqa.selenium.StaleElementReferenceException)13 Actions (org.openqa.selenium.interactions.Actions)13 CerberusEventException (org.cerberus.exception.CerberusEventException)12