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());
}
}
}
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());
}
}
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());
}
}
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);
}
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()), ' 	 
', ''),'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()), ' 	 
', ' '),'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);
}
Aggregations