List of usage examples for org.openqa.selenium WebElement isEnabled
boolean isEnabled();
From source file:ui.auto.core.utils.WebDriverUtils.java
License:Apache License
public WebElement waitForElement(final By by, long timeOut) { WebDriverWait wwait = new WebDriverWait(driver, timeOut / 1000); wwait.ignoring(NoSuchElementException.class, InvalidElementStateException.class); WebElement ajaxElement = wwait.until(new ExpectedCondition<WebElement>() { @Override// www . ja va2 s. c o m public WebElement apply(WebDriver d) { WebElement el = d.findElement(by); if (el.isEnabled()) return el; return null; } }); return ajaxElement; }
From source file:ui.auto.core.utils.WebDriverUtils.java
License:Apache License
public WebElement waitForVisibleEnabledElement(final By by, long timeOut) { WebDriverWait wwait = new WebDriverWait(driver, timeOut / 1000); wwait.ignoring(NoSuchElementException.class, ElementNotVisibleException.class); wwait.ignoring(InvalidElementStateException.class); WebElement ajaxElement = wwait.until(new ExpectedCondition<WebElement>() { @Override//from w w w . j a v a2 s . co m public WebElement apply(WebDriver d) { WebElement el = d.findElement(by); if (el.isDisplayed() && el.isEnabled()) return el; return null; } }); return ajaxElement; }
From source file:xxx.web.comments.roomfordebate.NYTimesCommentsScraper.java
License:Apache License
/** * Downloads the page and rolls out the entire discussion using {@link FirefoxDriver}. * * @param articleUrl url, e.g. {@code http://www.nytimes.com/roomfordebate/2015/02/04/regulate-internet-providers/the-internet-is-back-to-solid-regulatory-ground} * @return generated HTML code of the entire page * @throws InterruptedException/*from w w w . j av a 2 s .c o m*/ */ public String readHTML(String articleUrl) throws InterruptedException { // load the url WebDriver driver = new FirefoxDriver(); driver.get(articleUrl); // roll-out the entire discussion List<WebElement> commentsExpandElements; do { commentsExpandElements = driver.findElements(By.cssSelector("div.comments-expand")); // click on each of them for (WebElement commentsExpandElement : commentsExpandElements) { // only if visible & enabled if (commentsExpandElement.isDisplayed() && commentsExpandElement.isEnabled()) { commentsExpandElement.click(); // give it some time to load new comments Thread.sleep(3000); } } } // until there is one remaining that doesn't do anything... while (commentsExpandElements.size() > 1); // get the html String result = driver.getPageSource(); // close firefox driver.close(); return result; }