Search in sources :

Example 56 with NoSuchElementException

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

the class MultilineLocalizedPageSearchTest method alternativeMultilineTextSearchTest.

@Test(enabled = true)
public void alternativeMultilineTextSearchTest() {
    List<WebElement> elements = driver.findElements(By.cssSelector(elementCssSelector));
    for (String line : elements.get(0).getText().split("\r?\n")) {
        try {
            WebElement result = super.findByCssSelectorAndInnerText(null, line.replaceAll("\r?", ""));
            if (result != null) {
                System.err.println("Result(text): " + result.getText());
                highlight(result, 1000);
            }
        } 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)

Example 57 with NoSuchElementException

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

the class MultilineLocalizedPageSearchTest method fullMultilineTextSearchTest.

@Test(enabled = true)
public void fullMultilineTextSearchTest() {
    WebElement element = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.cssSelector(elementCssSelector))));
    try {
        // trim it all - the findByCssSelectorAndInnerText uses textContent, that
        // is being trimmed
        WebElement result = super.findByCssSelectorAndInnerText(null, element.getText().replace("\n", "").replace("\r", ""));
        if (result != null) {
            System.err.println("Result(text): " + result.getText());
            highlight(result, 1000);
        } else {
            System.err.println("Nothing found.");
        }
    } 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)

Example 58 with NoSuchElementException

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

the class MultilineLocalizedPageSearchTest method failedMultilineTextSearchTest.

@Test(enabled = false)
public void failedMultilineTextSearchTest() {
    List<WebElement> elements = driver.findElements(By.cssSelector(elementCssSelector));
    assertTrue(elements.size() > 0);
    WebElement element = elements.get(0);
    try {
        element = wait.until(ExpectedConditions.visibilityOf(driver.findElement(By.xpath(String.format(complexXPathTemplate, searchString)))));
        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)

Example 59 with NoSuchElementException

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

the class FindingIdFromLabelForTest method findingIdVialabelTextXPathTest.

@Test(enabled = false)
public void findingIdVialabelTextXPathTest() {
    // Arrange
    System.err.println(String.format("Looking for label with text %s", text1));
    List<WebElement> labels = driver.findElements(By.xpath(String.format("//label[contains(text(), '%s')]", text1)));
    assertTrue(labels.size() > 0);
    WebElement label = labels.get(0);
    highlight(label);
    String selector = label.getAttribute("for");
    System.err.println(String.format("Label is for id: \"%s\"", selector));
    // Act
    try {
        WebElement inputElement = driver.findElement(By.id(selector));
        // Assert
        assertThat(inputElement, notNullValue());
        assertThat(inputElement.getAttribute("name"), equalTo("saleGroupId"));
        System.err.println(String.format("%s finds %s", selector, inputElement.getAttribute("name")));
        flash(inputElement);
    } catch (NoSuchElementException e) {
        System.err.println(String.format("%s leading to exception: %s...", selector, e.toString().substring(0, 200)));
    }
    sleep(100);
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) WebElement(org.openqa.selenium.WebElement) NoSuchElementException(org.openqa.selenium.NoSuchElementException) Test(org.testng.annotations.Test)

Example 60 with NoSuchElementException

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

the class CookiesIAgreeTest method selectCookieMessageXPathTest.

@Test(enabled = false)
public void selectCookieMessageXPathTest() {
    element = driver.findElement(By.id("cookie-law-info-bar"));
    assertThat(element, notNullValue());
    highlight(element, 100);
    if (debug) {
        System.err.println(element.getAttribute("innerHTML"));
    }
    // "I AGREE" button
    elements = driver.findElements(By.xpath("//a[contains(@class, 'button')]"));
    assertThat(elements.size(), greaterThan(0));
    // show every button. NOTE: time-consuming
    elements.stream().forEach(o -> {
        // NOTE: ignoring TimeoutException from highlight(o) and continue is quite
        // time consuming
        /*  often text element text appears empty */
        System.err.println("text: " + o.getText() + "html: " + o.getAttribute("outerHTML"));
        try {
            // no effect ?
            o.sendKeys(Keys.CONTROL + "t");
        } catch (ElementNotInteractableException e) {
            System.err.println("Exception (ignored): " + e.getMessage());
        }
    });
    element = driver.findElement(By.id("cc-button"));
    assertThat(element, notNullValue());
    // no exception but no visual effect
    highlight(element, 1000);
    if (debug) {
        System.err.println("text: " + element.getText() + "html: " + element.getAttribute("outerHTML"));
    }
    element = driver.findElements(By.xpath("//a[contains(@class, 'button')]")).stream().filter(o -> o.getText().trim().compareToIgnoreCase("I AGREE") > -1).collect(Collectors.toList()).get(0);
    assertThat(element, notNullValue());
    // no effect
    element.sendKeys(Keys.CONTROL + "t");
    try {
        WebElement parentElement = driver.findElement(By.xpath("//a[@id = 'cc-button']")).findElement(By.xpath(".."));
        element = parentElement.findElement(By.xpath("//*[contains(normalize-space(text()),'I AGREE')]"));
        assertThat(element, notNullValue());
    } catch (NoSuchElementException e) {
    }
    // intensive tweaks
    for (String xpath : Arrays.asList(new String[] { "//a[contains(@class, 'button')][contains(translate(normalize-space(text()), ' &#9;&#10;&#13', ''),'IAGREE')]", "//a[contains(@class, 'button')][contains(translate(normalize-space(text()), ' ', ''),'IAGREE')]", "//a[contains(@class, 'button')][contains(normalize-space(text()),'I AGREE')]", "//a[contains(@class, 'button')][contains(text(),'I AGREE')]", "//a[contains(@class, 'button')][contains('.','I AGREE')]", "//a[contains(@class, 'button')][contains('.','EE')]", "//a[contains(@class, 'button')][contains('.','ee')]", "//a[contains(@class, 'button')][text() ='I AGREE']", "//*[@id = 'cc-button'][contains(normalize-space(text()),'')]", "//*[contains(@class ,'button')][contains(normalize-space(translate(text()), ' &#9;&#10;&#13', ' '),'Free Sign')]" })) {
        try {
            element = driver.findElement(By.xpath(xpath));
            assertThat(element, notNullValue());
            // 
            // no effect
            element.sendKeys(Keys.CONTROL + "t");
            highlight(element, 1000);
            // if (debug) {
            System.err.println("text: " + element.getText() + "html: " + element.getAttribute("outerHTML"));
        // }
        } catch (NoSuchElementException | ElementNotInteractableException e) {
            System.err.println("Exception (ignored): " + e.getMessage());
        // check the *** Element info: {Using=xpath, value=...} part
        }
    }
    // "Learn more" link
    element = driver.findElement(By.xpath("//a[@href][contains(text(),\"Learn more\")]"));
    assertThat(element, notNullValue());
    // highlight(agreeButtonElement, 1000);
    if (debug) {
        System.err.println(element.getAttribute("outerHTML"));
    }
    element = driver.findElement(By.tagName("body"));
    if (debug) {
        System.err.println(element.getAttribute("tagName"));
    }
    // based on:
    // https://stackoverflow.com/questions/17547473/how-to-open-a-new-tab-using-selenium-webdriver
    // no effect
    element.sendKeys(Keys.CONTROL + "t");
    // actions.keyDown(Keys.CONTROL).build().perform();
    // actions.keyUp(Keys.CONTROL).build().perform();
    // actions.keyDown().build().perform();
    sleep(10000);
}
Also used : Arrays(java.util.Arrays) Wait(org.openqa.selenium.support.ui.Wait) Keys(org.openqa.selenium.Keys) By(org.openqa.selenium.By) WebDriver(org.openqa.selenium.WebDriver) BeforeMethod(org.testng.annotations.BeforeMethod) WebElement(org.openqa.selenium.WebElement) Test(org.testng.annotations.Test) ElementNotInteractableException(org.openqa.selenium.ElementNotInteractableException) Collectors(java.util.stream.Collectors) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) ArrayList(java.util.ArrayList) TimeUnit(java.util.concurrent.TimeUnit) NoSuchElementException(org.openqa.selenium.NoSuchElementException) FluentWait(org.openqa.selenium.support.ui.FluentWait) List(java.util.List) Matchers.greaterThan(org.hamcrest.Matchers.greaterThan) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) ElementNotInteractableException(org.openqa.selenium.ElementNotInteractableException) WebElement(org.openqa.selenium.WebElement) 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