List of usage examples for org.openqa.selenium WebElement isEnabled
boolean isEnabled();
From source file:com.ecofactor.qa.automation.platform.util.Pageutil.java
License:Open Source License
/** * Gets the element by the containing text. * @param driver the driver/*from w ww. jav a2 s .c om*/ * @param locator the locator * @param textValue the text value * @param timeout the timeout * @return the element by text contains */ public static WebElement getElementByTextContains(final WebDriver driver, final By locator, final String textValue, final CustomTimeout timeout) { WebElement elementAttrValue = null; final List<WebElement> elementList = getElements(driver, locator, timeout); for (final WebElement webElement : elementList) { final String valueAttribute = webElement.getText().trim(); if (webElement.isDisplayed() && webElement.isEnabled() && valueAttribute.trim().contains(textValue)) { elementAttrValue = webElement; } } return elementAttrValue; }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Sets the value./*from ww w .j av a 2 s . co m*/ * @param driver the driver * @param cssSelector the css selector * @param value the value */ public static void setValueByCSS(WebDriver driver, String cssSelector, String value) { if (isDisplayedByCSS(driver, cssSelector, 10)) { List<WebElement> inputs = driver.findElements(By.cssSelector(cssSelector)); for (WebElement input : inputs) { if (input.isDisplayed() && input.isEnabled()) { input.clear(); input.sendKeys(value); } } } }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Sets the value.//from w w w . j a v a 2 s .c o m * @param driver the driver * @param cssSelector the css selector * @param value the value * @param index the index */ public static void setValueByCSS(WebDriver driver, String cssSelector, String value, int index) { if (isDisplayedByCSS(driver, cssSelector, 10)) { List<WebElement> inputs = driver.findElements(By.cssSelector(cssSelector)); int count = 0; for (WebElement input : inputs) { if (input.isDisplayed() && input.isEnabled()) { if (count == index) { input.clear(); input.sendKeys(value); logger.info("Count " + count + ", " + input.getAttribute("id")); break; } ++count; } } } }
From source file:com.ecofactor.qa.automation.util.PageUtil.java
License:Open Source License
/** * Select option by value./*from w ww . j a v a2 s . co m*/ * @param driver the driver * @param cssSelector the css selector * @param selectValue the select value */ public static void selectOptionValueByCSS(final WebDriver driver, final String cssSelector, final String selectValue) { logger.info("Select css selector:" + cssSelector + " ; selectValue" + selectValue); List<WebElement> elements = driver.findElements(By.cssSelector(cssSelector)); for (WebElement element : elements) { if (element.isDisplayed() && element.isEnabled()) { Select select = new Select(element); select.selectByValue(selectValue); } } }
From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java
License:Apache License
public static boolean assertNull(WebElement element) { try {/*w w w. j a v a 2 s.co m*/ // call any method on the element element.isEnabled(); } catch (Exception ex) { return true; } return false; }
From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java
License:Apache License
public static boolean assertNotNull(WebElement element) { try {//from w ww .j a va2 s . c o m // call any method on the element element.isEnabled(); } catch (Exception ex) { return false; } return true; }
From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java
License:Apache License
public static WebElement waitForEnabled(WebDriver driver, String elementNameOrID, long timeout) { long start = System.currentTimeMillis(); WebElement webElement = null; while (null == webElement || !webElement.isEnabled()) { webElement = getByNameOrID(driver, elementNameOrID); if (null != webElement && webElement.isEnabled()) break; Assert.assertTrue(// ww w. ja v a 2s.com "Timeout (>" + timeout + "ms) while waiting for web element " + elementNameOrID + " to be enabled in page '" + driver.getTitle() + "'", System.currentTimeMillis() - start < timeout); waitForASecond(); } return webElement; }
From source file:com.francetelecom.clara.cloud.webapp.acceptancetest.utils.SeleniumUtils.java
License:Apache License
public static WebElement waitForEnabled(WebElement element, long timeout) { long start = System.currentTimeMillis(); while (!element.isEnabled()) { Assert.assertTrue("Timeout (>" + timeout + "ms) while waiting for web element " + element.toString() + " to be enabled", System.currentTimeMillis() - start < timeout); waitForASecond();/*from www .j a va 2s. co m*/ } return element; }
From source file:com.gargoylesoftware.htmlunit.javascript.host.html.HTMLInputElementTest.java
License:Apache License
/** * @throws Exception if the test fails/*from w w w. jav a 2s .c o m*/ */ @Test @Alerts({ "false", "true", "false", "true", "false", "true" }) public void disabledAttribute() throws Exception { final String html = HtmlPageTest.STANDARDS_MODE_PREFIX_ + "<html><head><title>foo</title><script>\n" + "function test() {\n" + " alert(document.form1.button1.disabled);\n" + " alert(document.form1.button2.disabled);\n" + " alert(document.form1.button3.disabled);\n" + " document.form1.button1.disabled = true;\n" + " document.form1.button2.disabled = false;\n" + " document.form1.button3.disabled = true;\n" + " alert(document.form1.button1.disabled);\n" + " alert(document.form1.button2.disabled);\n" + " alert(document.form1.button3.disabled);\n" + "}\n" + "</script></head><body>\n" + "<p>hello world</p>\n" + "<form name='form1'>\n" + " <input type='submit' name='button1' value='1'/>\n" + " <input type='submit' name='button2' value='2' disabled/>\n" + " <input type='submit' name='button3' value='3'/>\n" + "</form>\n" + "<a href='javascript:test()' id='clickme'>click me</a>\n" + "</body></html>"; final WebDriver driver = loadPage2(html); final WebElement button1 = driver.findElement(By.name("button1")); final WebElement button2 = driver.findElement(By.name("button2")); final WebElement button3 = driver.findElement(By.name("button3")); assertTrue(button1.isEnabled()); assertFalse(button2.isEnabled()); assertTrue(button3.isEnabled()); driver.findElement(By.id("clickme")).click(); verifyAlerts(driver, getExpectedAlerts()); assertFalse(button1.isEnabled()); assertTrue(button2.isEnabled()); assertFalse(button3.isEnabled()); }
From source file:com.github.jjYBdx4IL.test.selenium.SeleniumTestBaseTest.java
License:Apache License
/** * Wait until there is some element returned by {@link #findElement} which is displayed and enabled. The * timeout is given by {@link #CLICK_WAIT4ELEMENT_MILLIS}. * * @param text the text value of the element to select * @return// w w w .j a v a 2 s . c o m * @throws WebElementNotFoundException */ public WebElement waitForElement(String text, Boolean displayed, Boolean enabled) throws WebElementNotFoundException { log.info("waitForElement(" + text + ")"); WebElement e = null; long timeout = System.currentTimeMillis() + CLICK_WAIT4ELEMENT_MILLIS; do { try { e = findElement(text); if (e != null && enabled != null && enabled.booleanValue() != e.isEnabled()) { e = null; } if (e != null && displayed != null && displayed.booleanValue() != e.isDisplayed()) { e = null; } } catch (StaleElementReferenceException ex) { e = null; } if (e == null) { try { Thread.sleep(CLICK_WAIT4ELEMENT_POLL_MILLIS); } catch (InterruptedException ex) { } } } while ((e == null) && System.currentTimeMillis() < timeout); if (e == null) { throw new WebElementNotFoundException(text); } return e; }