@Override public boolean apply(Driver driver, WebElement element) { return element.isDisplayed(); } };
@Override public boolean apply(Driver driver, WebElement element) { try { element.isDisplayed(); return true; } catch (StaleElementReferenceException e) { return false; } } };
@Override public boolean apply(Driver driver, WebElement element) { try { return !element.isDisplayed(); } catch (StaleElementReferenceException elementHasDisappeared) { return true; } } };
private Describe isDisplayed(WebElement element) { try { if (!element.isDisplayed()) { sb.append(' ').append("displayed:false"); } } catch (UnsupportedOperationException e) { sb.append(' ').append("displayed:").append(e); } catch (InvalidElementStateException e) { sb.append(' ').append("displayed:").append(e); } return this; }
@Override public boolean isVisible() { try { return getWebElement().isDisplayed(); } catch (StaleElementReferenceException e) { return false; } }
@Override public Boolean execute(SelenideElement proxy, WebElementSource locator, Object[] args) { try { WebElement element = locator.getWebElement(); return element != null && element.isDisplayed(); } catch (WebDriverException | ElementNotFound elementNotFound) { if (Cleanup.of.isInvalidSelectorError(elementNotFound)) { throw Cleanup.of.wrap(elementNotFound); } return false; } catch (IndexOutOfBoundsException invalidElementIndex) { return false; } } }
@Override public WebElement execute(SelenideElement proxy, WebElementSource locator, Object[] args) { boolean selected = (Boolean) args[0]; WebElement element = locator.getWebElement(); if (!element.isDisplayed()) { throw new InvalidStateException(locator.driver(), "Cannot change invisible element"); } String tag = element.getTagName(); if (!tag.equals("option")) { if (tag.equals("input")) { String type = element.getAttribute("type"); if (!type.equals("checkbox") && !type.equals("radio")) { throw new InvalidStateException(locator.driver(), "Only use setSelected on checkbox/option/radio"); } } else { throw new InvalidStateException(locator.driver(), "Only use setSelected on checkbox/option/radio"); } } if (element.getAttribute("readonly") != null || element.getAttribute("disabled") != null) { throw new InvalidStateException(locator.driver(), "Cannot change value of readonly/disabled element"); } if (element.isSelected() != selected) { click.execute(proxy, locator, NO_ARGS); } return proxy; } }
@Test public void theHeaderDropdown() throws Exception { Assert.assertNotNull(asOnHomePage.getUsernameElement()); Assert.assertFalse(asOnHomePage.getAccountSettingsElement().isDisplayed()); Assert.assertFalse(asOnHomePage.getSignOutElement().isDisplayed()); asOnHomePage.getUsernameElement().click(); Assert.assertTrue(asOnHomePage.getAccountSettingsElement().isDisplayed()); Assert.assertTrue(asOnHomePage.getSignOutElement().isDisplayed()); asOnHomePage.getAccountSettingsElement().click(); Assert.assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Account Settings")); }
protected static void doSimpleExplore(BrowserWebDriverContainer rule) { RemoteWebDriver driver = setupDriverFromRule(rule); driver.get("http://en.wikipedia.org/wiki/Randomness"); // Oh! The irony! assertTrue("Randomness' description has the word 'pattern'", driver.findElementByPartialLinkText("pattern").isDisplayed()); }
@Test public void displaysErrorWhenPasswordContravenesPolicy() { //the only policy we can contravene by default is the length String newPassword = new RandomValueStringGenerator(260).generate(); webDriver.get(baseUrl + "/change_password"); signIn(userEmail, PASSWORD); changePassword(PASSWORD, newPassword, newPassword); WebElement errorMessage = webDriver.findElement(By.className("error-message")); assertTrue(errorMessage.isDisplayed()); assertEquals("Password must be no more than 255 characters in length.", errorMessage.getText()); }
@Test public void testChangePassword() throws Exception { webDriver.get(baseUrl + "/change_password"); signIn(userEmail, PASSWORD); changePassword(PASSWORD, NEW_PASSWORD, "new"); WebElement errorMessage = webDriver.findElement(By.className("error-message")); assertTrue(errorMessage.isDisplayed()); assertEquals("Passwords must match and not be empty.", errorMessage.getText()); changePassword(PASSWORD, NEW_PASSWORD, NEW_PASSWORD); signOut(); signIn(userEmail, NEW_PASSWORD); }
public static final Condition hidden = new Condition("hidden", true) { @Override public boolean apply(WebElement element) { try { return !element.isDisplayed(); } catch (StaleElementReferenceException elementHasDisappeared) { return true; } } };
/** * Returns true if the status message modal is visible. */ public boolean isFormSubmissionStatusMessageVisible() { return copyModalStatusMessage.isDisplayed(); }
public boolean isElementVisible(String elementId) { try { return browser.driver.findElement(By.id(elementId)).isDisplayed(); } catch (NoSuchElementException e) { return false; } }
public boolean verifyDuplicateButtonIsDisplayed(int qnIndex) { WebElement duplicateBn = browser.driver.findElement( By.xpath("//a[contains(@class, 'btn-duplicate-qn')][@data-qnnumber='" + qnIndex + "']")); return duplicateBn.isDisplayed(); }
public boolean isNamedElementVisible(String elementName) { try { return browser.driver.findElement(By.name(elementName)).isDisplayed(); } catch (NoSuchElementException e) { return false; } }
public boolean isDiscardChangesButtonVisible(int qnIndex) { WebElement discardChangesButton = browser.driver.findElement( By.xpath("//a[contains(@class, 'btn-discard-changes')][@data-qnnumber='" + qnIndex + "']")); return discardChangesButton.isDisplayed(); }
public void verifyPanelForParticipantIsDisplayed(String participantIdentifier) { WebElement panel = browser.driver.findElement( By.xpath("//div[contains(@class, 'panel-primary') or contains(@class, 'panel-default')]" + "[contains(.,'[" + participantIdentifier + "]')]")); assertTrue(panel.isDisplayed()); }
/** * Checks if the course edit form is enabled. * @return true if the course edit form is enabled */ public boolean isCourseEditFormEnabled() { return !courseIdTextBox.isEnabled() && courseNameTextBox.isEnabled() && saveCourseButton.isDisplayed(); }
public boolean clickShowNewInstructorFormButton() { click(showNewInstructorFormButton); return newInstructorNameTextBox.isEnabled() && newInstructorEmailTextBox.isEnabled() && addInstructorButton.isDisplayed(); }