List of usage examples for org.openqa.selenium WebElement isEnabled
boolean isEnabled();
From source file:com.cognifide.qa.bb.aem.core.component.dialog.dialogfields.text.FontFormat.java
License:Apache License
private void clickFormatButton(WebElement button) { controlToolbar.selectText(); bobcatWait.until(input -> button.isEnabled()); button.click(); }
From source file:com.cognifide.qa.bb.aem.touch.pageobjects.touchui.dialogfields.text.FontFormat.java
License:Apache License
private void clickFormatButton(WebElement button) { controlToolbar.selectText();/*from w w w . j a va 2s .c o m*/ bobcatWait.withTimeout(Timeouts.SMALL).until((ExpectedCondition<Object>) input -> button.isEnabled()); button.click(); }
From source file:com.cognifide.qa.bb.aem.touch.siteadmin.aem61.calendar.WaitForDynamicRedraw.java
License:Apache License
private ExpectedCondition<Boolean> dynamicRedrawFinishes(final WebElement element) { return new ExpectedCondition<Boolean>() { int retries = 3; @Override/* w w w . j a v a 2s . c o m*/ public Boolean apply(WebDriver ignored) { try { element.isEnabled(); } catch (StaleElementReferenceException expected) { if (retries > 0) { retries--; dynamicRedrawFinishes(element); } else { throw expected; } } return true; } }; }
From source file:com.comcast.dawg.house.AdvanceFilterNavigator.java
License:Apache License
/** * Helper method to verify if a button is enabled * @param parent The parent of the button * @param className The class name used to look it up in the parent * @param enabled true if the button should be enabled, false if it should be disabled *///from w ww .j av a 2 s . c o m private void assertEnabled(SearchContext parent, String className, boolean enabled) { WebElement btn = parent.findElement(By.className(className)); Assert.assertEquals(btn.isEnabled(), enabled); }
From source file:com.common.ExpectedConditions.java
License:Apache License
/** * An expectation for checking an element is visible and enabled such that you * can click it.// w w w .j a va 2 s .co m * * @param locator used to find the element * @return the WebElement once it is located and clickable (visible and enabled) */ public static ExpectedCondition<WebElement> elementToBeClickable(final By locator) { return new ExpectedCondition<WebElement>() { public ExpectedCondition<WebElement> visibilityOfElementLocated = ExpectedConditions .visibilityOfElementLocated(locator); @Override public WebElement apply(WebDriver driver) { WebElement element = visibilityOfElementLocated.apply(driver); try { if (element != null && element.isEnabled()) { return element; } else { return null; } } catch (StaleElementReferenceException e) { return null; } } @Override public String toString() { return "element to be clickable: " + locator; } }; }
From source file:com.common.ExpectedConditions.java
License:Apache License
/** * An expectation for checking an element is visible and enabled such that you * can click it./*from www . j a va 2 s . co m*/ * * @param element the WebElement * @return the (same) WebElement once it is clickable (visible and enabled) */ public static ExpectedCondition<WebElement> elementToBeClickable(final WebElement element) { return new ExpectedCondition<WebElement>() { public ExpectedCondition<WebElement> visibilityOfElement = ExpectedConditions.visibilityOf(element); @Override public WebElement apply(WebDriver driver) { WebElement element = visibilityOfElement.apply(driver); try { if (element != null && element.isEnabled()) { return element; } else { return null; } } catch (StaleElementReferenceException e) { return null; } } @Override public String toString() { return "element to be clickable: " + element; } }; }
From source file:com.common.ExpectedConditions.java
License:Apache License
/** * Wait until an element is no longer attached to the DOM. * * @param element The element to wait for. * @return false is the element is still attached to the DOM, true * otherwise.//from ww w.j a va 2 s.c o m */ public static ExpectedCondition<Boolean> stalenessOf(final WebElement element) { return new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver ignored) { try { // Calling any method forces a staleness check element.isEnabled(); return false; } catch (StaleElementReferenceException expected) { return true; } } @Override public String toString() { return String.format("element (%s) to become stale", element); } }; }
From source file:com.consol.citrus.cucumber.step.runner.selenium.SeleniumStepsTest.java
License:Apache License
@Test public void testClick() { SeleniumBrowserConfiguration endpointConfiguration = new SeleniumBrowserConfiguration(); when(seleniumBrowser.getName()).thenReturn("seleniumBrowser"); when(seleniumBrowser.getWebDriver()).thenReturn(webDriver); when(seleniumBrowser.getEndpointConfiguration()).thenReturn(endpointConfiguration); WebElement element = Mockito.mock(WebElement.class); when(element.isDisplayed()).thenReturn(true); when(element.isEnabled()).thenReturn(true); when(element.getTagName()).thenReturn("button"); when(webDriver.findElement(any(By.class))).thenAnswer(invocation -> { By select = (By) invocation.getArguments()[0]; Assert.assertEquals(select.getClass(), By.ById.class); Assert.assertEquals(select.toString(), "By.id: foo"); return element; });/*from w w w .j a v a 2 s. c o m*/ steps.setBrowser("seleniumBrowser"); steps.click("id", "foo"); Assert.assertEquals(runner.getTestCase().getActionCount(), 1L); Assert.assertTrue(((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate() instanceof SeleniumAction); SeleniumAction action = (SeleniumAction) ((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate(); Assert.assertEquals(action.getBrowser(), seleniumBrowser); Assert.assertTrue(action instanceof ClickAction); Assert.assertEquals(((ClickAction) action).getProperty(), "id"); Assert.assertEquals(((ClickAction) action).getPropertyValue(), "foo"); verify(element).click(); }
From source file:com.consol.citrus.cucumber.step.runner.selenium.SeleniumStepsTest.java
License:Apache License
@Test public void testSetInput() { SeleniumBrowserConfiguration endpointConfiguration = new SeleniumBrowserConfiguration(); when(seleniumBrowser.getName()).thenReturn("seleniumBrowser"); when(seleniumBrowser.getWebDriver()).thenReturn(webDriver); when(seleniumBrowser.getEndpointConfiguration()).thenReturn(endpointConfiguration); WebElement element = Mockito.mock(WebElement.class); when(element.isDisplayed()).thenReturn(true); when(element.isEnabled()).thenReturn(true); when(element.getTagName()).thenReturn("input"); when(webDriver.findElement(any(By.class))).thenReturn(element); steps.setBrowser("seleniumBrowser"); steps.setInput("Hello", "id", "foo"); Assert.assertEquals(runner.getTestCase().getActionCount(), 1L); Assert.assertTrue(((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate() instanceof SeleniumAction); SeleniumAction action = (SeleniumAction) ((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate();/*from ww w.j a v a2 s . co m*/ Assert.assertEquals(action.getBrowser(), seleniumBrowser); Assert.assertTrue(action instanceof SetInputAction); Assert.assertEquals(((SetInputAction) action).getValue(), "Hello"); Assert.assertEquals(((SetInputAction) action).getProperty(), "id"); Assert.assertEquals(((SetInputAction) action).getPropertyValue(), "foo"); verify(element).clear(); verify(element).sendKeys("Hello"); }
From source file:com.consol.citrus.cucumber.step.runner.selenium.SeleniumStepsTest.java
License:Apache License
@Test public void testCheckInput() { SeleniumBrowserConfiguration endpointConfiguration = new SeleniumBrowserConfiguration(); when(seleniumBrowser.getName()).thenReturn("seleniumBrowser"); when(seleniumBrowser.getWebDriver()).thenReturn(webDriver); when(seleniumBrowser.getEndpointConfiguration()).thenReturn(endpointConfiguration); WebElement element = Mockito.mock(WebElement.class); when(element.isDisplayed()).thenReturn(true); when(element.isEnabled()).thenReturn(true); when(element.getTagName()).thenReturn("input"); when(webDriver.findElement(any(By.class))).thenReturn(element); steps.setBrowser("seleniumBrowser"); steps.checkInput("check", "id", "foo"); Assert.assertEquals(runner.getTestCase().getActionCount(), 1L); Assert.assertTrue(((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate() instanceof SeleniumAction); SeleniumAction action = (SeleniumAction) ((DelegatingTestAction) runner.getTestCase().getTestAction(0)) .getDelegate();/*from w ww. j av a2 s. c o m*/ Assert.assertEquals(action.getBrowser(), seleniumBrowser); Assert.assertTrue(action instanceof CheckInputAction); Assert.assertEquals(((CheckInputAction) action).isChecked(), true); Assert.assertEquals(((CheckInputAction) action).getProperty(), "id"); Assert.assertEquals(((CheckInputAction) action).getPropertyValue(), "foo"); verify(element).click(); }