List of usage examples for org.openqa.selenium WebElement isDisplayed
boolean isDisplayed();
From source file:io.tourniquet.pageobjects.PageObjectsInjectorTest.java
License:Apache License
@Test public void testAbstractGroup_SubmitForm() throws Exception { //prepare/*from ww w .j a v a 2 s . c om*/ new SeleniumContext(() -> driver).init(); WebElement element = mock(WebElement.class); when(driver.findElement(By.id("someForm"))).thenReturn(element); when(element.isDisplayed()).thenReturn(true); when(element.getTagName()).thenReturn("form"); GroupWithAbstractSubgroup group = new GroupWithAbstractSubgroup(); //act PageObjectsInjector.injectFields(group); //assert assertNotNull(group.subgroup); group.subgroup.submitForm(); verify(element).submit(); assertEquals("testpage", group.subgroup.toString()); }
From source file:io.tourniquet.pageobjects.PageObjectsInjectorTest.java
License:Apache License
@Test public void testAbstractGroup_sendKeys() throws Exception { //prepare/* www . j av a2 s.co m*/ new SeleniumContext(() -> driver).init(); WebElement element = mock(WebElement.class); when(driver.findElement(By.id("someInput"))).thenReturn(element); when(element.isDisplayed()).thenReturn(true); GroupWithAbstractSubgroup group = new GroupWithAbstractSubgroup(); //act PageObjectsInjector.injectFields(group); //assert assertNotNull(group.subgroup); AbstractGroup fluentPage = group.subgroup.enterValue("text"); verify(element).clear(); verify(element).sendKeys("text"); assertNotNull(fluentPage); assertEquals(group.subgroup, fluentPage); assertEquals("testpage", fluentPage.toString()); }
From source file:io.tourniquet.pageobjects.PageObjectsInjectorTest.java
License:Apache License
@Test(expected = IllegalArgumentException.class) public void testAbstractGroup_twoManyArgs() throws Exception { //prepare// w ww .jav a 2 s . c o m new SeleniumContext(() -> driver).init(); WebElement element = mock(WebElement.class); when(driver.findElement(By.id("someInput"))).thenReturn(element); when(element.isDisplayed()).thenReturn(true); GroupWithAbstractSubgroup group = new GroupWithAbstractSubgroup(); //act PageObjectsInjector.injectFields(group); //assert assertNotNull(group.subgroup); //this method is not supported group.subgroup.twoParamsMethod("text", "2ndParam"); }
From source file:io.wcm.qa.galenium.testcase.AbstractGaleniumInteractiveBaseTestCase.java
License:Apache License
protected void mouseOver(Selector selector) { getLogger().debug("attempting mouse over: " + selector.elementName()); WebDriver driver = getDriver();/*from w ww. ja v a 2 s. c om*/ List<WebElement> mouseOverElements = driver.findElements(selector.asBy()); if (!mouseOverElements.isEmpty()) { WebElement mouseOverElement = mouseOverElements.get(0); if (mouseOverElement.isDisplayed()) { getLogger().debug("Moving to element: " + mouseOverElement); Actions actions = new Actions(driver); actions.moveToElement(mouseOverElement).perform(); } } else { getLogger().debug("no elements found."); } }
From source file:io.wcm.qa.galenium.testcase.AbstractGaleniumInteractiveBaseTestCase.java
License:Apache License
protected void clickVisibleOfMany(Selector selector) { List<WebElement> elements = findElements(selector); for (WebElement element : elements) { getLogger().debug("found element with " + selector.elementName() + ": " + element); if (element.isDisplayed()) { getLogger().debug("clicking element: " + element); element.click();/*from w ww . j a v a 2 s . c om*/ return; } } }
From source file:jhc.redsniff.webdriver.ExtraExpectedConditions.java
License:Apache License
public static ExpectedCondition<Boolean> visibilityOfAny(final MFinder<WebElement, SearchContext> finder) { return new ExpectedCondition<Boolean>() { @Override// ww w.java 2s . c o m public Boolean apply(WebDriver driver) { Collection<WebElement> foundElements = checkerFor((SearchContext) driver) .thatWhichIsFoundBy(expectationOfSome(finder)); //TODO - wrap in a that() matcher so don't need the exception check here - //although care needed for the invisibility version - does stale mean can assume invisible? not sure if (foundElements.isEmpty()) return false; else { for (WebElement element : foundElements) { try { if (element.isDisplayed()) return true; } catch (StaleElementReferenceException e) { // skip - implies not displayed } } return false; } } @Override public String toString() { return newDescription().appendDescriptionOf(finder).appendText(" to be visible").toString(); } }; }
From source file:jhc.redsniff.webdriver.ExtraExpectedConditions.java
License:Apache License
public static ExpectedCondition<Boolean> invisibilityOf(final MFinder<WebElement, SearchContext> finder) { return new ExpectedCondition<Boolean>() { @Override/*w w w. ja v a 2 s . c o m*/ public Boolean apply(WebDriver driver) { Collection<WebElement> foundElements = checkerFor((SearchContext) driver) .thatWhichIsFoundBy(expectationOfSome(finder)); if (foundElements.isEmpty()) return true; else { for (WebElement element : foundElements) { try { if (element.isDisplayed()) return false; } catch (StaleElementReferenceException e) { } // if stale this implies element is not displayed so we can skip over it } return true; } } @Override public String toString() { return newDescription().appendDescriptionOf(finder).appendText(" to be invisible or not present") .toString(); } }; }
From source file:jhc.redsniff.webdriver.matchers.ElementDisplayedMatcher.java
License:Apache License
@Override protected ElementDisplayedState stateOf(WebElement element) { return element.isDisplayed() ? DISPLAYED : HIDDEN; }
From source file:jj.webdriver.finder.ImpatientWebElementFinder.java
License:Apache License
@Override public WebElement find(final WebDriver webDriver, final By by) { int tries = 1; do {//from w ww . j a v a2 s . com try { new WebDriverWait(webDriver, 3).until(new Predicate<WebDriver>() { @Override public boolean apply(WebDriver webDriver) { WebElement webElement = webDriver.findElement(by); return webElement != null && webElement.isDisplayed(); } }); // if we succeed, exit now tries = 0; } catch (TimeoutException e) { if (tries == 0) { throw new AssertionError("gave up locating an element after 6 seconds " + by); } else { logger.warn("can't find element {} in 3 seconds. trying three more.", by); } } } while (tries-- > 0); return webDriver.findElement(by); }
From source file:jj.webdriver.finder.ThreeSecondsAndDisplayedWebElementFinder.java
License:Apache License
@Override public WebElement find(final WebDriver webDriver, final By by) { try {/*ww w . j a v a 2 s . com*/ new WebDriverWait(webDriver, 3).until(new Predicate<WebDriver>() { @Override public boolean apply(WebDriver webDriver) { WebElement webElement = webDriver.findElement(by); return webElement != null && webElement.isDisplayed(); } }); } catch (TimeoutException e) { throw new AssertionError("could not locate an element " + by); } return webDriver.findElement(by); }