Java Code Examples for org.openqa.selenium.WebElement.isDisplayed()

The following are Jave code examples for showing how to use isDisplayed() of the org.openqa.selenium.WebElement class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: POM_HYBRID_FRAMEOWRK   File: WebUtilities.java   View Source Code Vote up 7 votes
/**
 * Wait for element to appear.
 *
 * @param driver the driver
 * @param element the element
 * @param logger the logger
 */
public static boolean waitForElementToAppear(WebDriver driver, WebElement element, ExtentTest logger) {
	boolean webElementPresence = false;
	try {
		Wait<WebDriver> fluentWait = new FluentWait<WebDriver>(driver).pollingEvery(2, TimeUnit.SECONDS)
				.withTimeout(60, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
		fluentWait.until(ExpectedConditions.visibilityOf(element));
		if (element.isDisplayed()) {
			webElementPresence= true;
		}
	} catch (TimeoutException toe) {
		logger.log(LogStatus.ERROR, "Timeout waiting for webelement to be present<br></br>" + toe.getStackTrace());
	} catch (Exception e) {
		logger.log(LogStatus.ERROR, "Exception occured<br></br>" + e.getStackTrace());
	}
	return webElementPresence;
}
 
Example 2
Project: NoraUi   File: Utilities.java   View Source Code Vote up 6 votes
/**
 * An expectation for checking that nb elements present on the web page that match the locator
 * are visible. Visibility means that the elements are not only displayed but also have a height
 * and width that is greater than 0.
 *
 * @param locator
 *            used to find the element
 * @param nb
 *            is exactly number of responses
 * @return the list of WebElements once they are located
 */
public static ExpectedCondition<List<WebElement>> visibilityOfNbElementsLocatedBy(final By locator, final int nb) {
    return new ExpectedCondition<List<WebElement>>() {
        @Override
        public List<WebElement> apply(WebDriver driver) {
            int nbElementIsDisplayed = 0;
            final List<WebElement> elements = driver.findElements(locator);
            for (final WebElement element : elements) {
                if (element.isDisplayed()) {
                    nbElementIsDisplayed++;
                }
            }
            return nbElementIsDisplayed == nb ? elements : null;
        }
    };
}
 
Example 3
Project: ToDoMVCEmberJS   File: BasicTodoMvcPage.java   View Source Code Vote up 6 votes
@Step("Rreactivate the item")
public boolean reActivateItem(String itemName){
    WebElement todoItem = driver.findElement(By.xpath("//label[.='" + itemName + "']"));
    WebElement divClass = todoItem.findElement(By.xpath(".."));
    WebElement chkComplete = divClass.findElement(By.tagName("input"));
    chkComplete.click();
    WebElement liClass = null;
    try{
        liClass = divClass.findElement(By.xpath(".//*[@id='clear-completed']"));
        if (liClass.isDisplayed()){
            return false;
        }
    }catch (Exception e){
    }
    return true;
}
 
Example 4
Project: xtf   File: DriverUtil.java   View Source Code Vote up 6 votes
public static void waitFor(WebDriver driver, long timeout, By... elements) throws TimeoutException, InterruptedException {
	try {
		WaitUtil.waitFor(() -> elementsPresent(driver, elements), null, 1000L, timeout);
	} catch (TimeoutException ex) {
		try {
			for (By element : elements) {
				WebElement webElement = driver.findElement(element);
				if (!webElement.isDisplayed()) {
					throw new TimeoutException("Timeout exception during waiting for web element: " + webElement.getText());
				}
			}
		} catch (NoSuchElementException | StaleElementReferenceException x) {
			throw new TimeoutException("Timeout exception during waiting for web element: " + x.getMessage());
		}
	}
}
 
Example 5
Project: Cognizant-Intelligent-Test-Scripter   File: CheckBox.java   View Source Code Vote up 6 votes
@Action(object = ObjectType.BROWSER, desc = "Check all the check boxes in the context")
public void checkAllCheckBoxes() {
    try {
        List<WebElement> checkboxes = Driver.findElements(By.cssSelector("input[type=checkbox]"));
        if (checkboxes.isEmpty()) {
            Report.updateTestLog(Action, "No Checkbox present in the page", Status.WARNING);
        } else {
            for (WebElement checkbox : checkboxes) {
                if (checkbox.isDisplayed() && !checkbox.isSelected()) {
                    checkbox.click();
                }
            }
            Report.updateTestLog(Action, "All checkboxes are checked", Status.PASS);
        }
    } catch (Exception ex) {
        Report.updateTestLog(Action, "Error while checking checkboxes - " + ex, Status.FAIL);
        Logger.getLogger(CheckBox.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 6
Project: Cognizant-Intelligent-Test-Scripter   File: SampleScript.java   View Source Code Vote up 6 votes
public void handleCondition(String argumentShouldNotBeGiven
/**
 * No argument should be specifed Then only will be executed[show in
 * action column]
 */
) throws UnCaughtException {
    //Getting object from the object repository
    WebElement element = AObject.findElement("ObjectName", "PageName");
    //Putting condition on object
    if (element.isDisplayed()) {
        //Calling another test case if the condition is matched
        //Pass the Scenario name,Test case name and sub-iteration index
        executeTestCase("testscenario1", "cancelTicket", 1);
        Report.updateTestLog("Userdefined Action ", "inside reusable", Status.PASS);
        //If needed you can break the test case also by calling existing functions
        executeMethod("StopBrowser");
        //
    } else {
        Report.updateTestLog("Userdefined Action ", "switch to origional", Status.DONE);
    }
}
 
Example 7
Project: teasy   File: FrameAwareWebElementTransformerTest.java   View Source Code Vote up 5 votes
@Test(enabled = false, expectedExceptions = StaleElementReferenceException.class)
public void testTryToAccessToStolenElement() {
    final WebElement stolenElement = givenStolenElement();
    final WebElement transformedStolenElement = transformer.apply(stolenElement);

    transformedStolenElement.isDisplayed();
}
 
Example 8
Project: phoenix.webui.framework   File: SeleniumMultiValueEditor.java   View Source Code Vote up 5 votes
@Override
public void setValue(Element ele, Object value)
{
    ElementsSearchStrategy<WebElement> strategy = searchStrategyUtils.findElementsStrategy(WebElement.class, ele);
    
    List<WebElement> eleList = strategy.searchAll(ele);
    
    for(int i = 0; i < eleList.size(); i++)
    {
        WebElement webEle = eleList.get(i);
        String tagName = webEle.getTagName();
        String text = webEle.getText();
        
        String attrName = null;
        String attrValue = null;
        
        if(!webEle.isDisplayed())
        {
            continue;
        }
        
        if(filter.filter(tagName, attrName, attrValue, text))
        {
            webEle.sendKeys(value.toString());
        }
    }
}
 
Example 9
Project: saladium   File: SaladiumDriver.java   View Source Code Vote up 5 votes
@Override
public void selectionner(String type, String selector, String valeur) {
    this.logger.info("selectionner(type" + type + ", selector" + selector + ", valeur" + valeur + ")");
    try {
        By locator = BySelec.get(type, selector);
        WebElement elem = wait.until(ExpectedConditions.presenceOfElementLocated(locator));
        String tagName = elem.getTagName();
        if (tagName.equals("select")) {
            Select select = new Select(elem);
            // List<WebElement> options = select.getAllSelectedOptions();
            // Iterator<WebElement> it = options.iterator();
            // while (it.hasNext()) {
            // WebElement webElement = it.next();
            // if ("auto".equals(webElement.getCssValue("z-index"))) {
            // if (!webElement.isDisplayed()) {
            // System.out.println("################### !isDisplayed()");
            // }
            // System.out.println("################### cssValue " + webElement.getCssValue("z-index"));
            // }
            // }
            select.selectByVisibleText(valeur);
            // Thread.sleep(1000);
        } else {
            elem.click();
            List<WebElement> children = elem.findElements(
                By.xpath("//div[@class='listComboBoxElement']/li"));
            Iterator<WebElement> it = children.iterator();
            boolean flag = false;
            do {
                WebElement webElement = it.next();
                if (webElement.getText().startsWith(valeur)) {
                    if (webElement.isDisplayed()) {
                        webElement.click();
                        flag = true;
                    }
                }
            } while (!flag && it.hasNext());
            if (!flag) {
                Assert.fail("Impossible de trouver la valeur :" + valeur
                    + " pour le champs :" + type + ":" + selector);
            }
        }
    } catch (NoSuchElementException | TimeoutException e) {
        String pathScreenShot = takeScreenShot();
        Assert.fail("Sélection impossible ! (type" + type + ", selector" + selector + ", valeur" + valeur + ") pathScreenShot=" + pathScreenShot);
    }
}
 
Example 10
Project: selenium-components   File: SeleniumConditions.java   View Source Code Vote up 5 votes
@Override
public Boolean get()
{
    WebElement element = elementSelector.get();

    return element != null && element.isDisplayed();
}
 
Example 11
Project: mot-automated-testsuite   File: WebDriverWrapper.java   View Source Code Vote up 5 votes
/**
 * Check if an element is visible.
 *
 * @param selector Selector to find the element.
 * @return Return whether the element is visible or not.
 */
public boolean isVisible(By selector) {
    WebElement element = webDriver.findElement(selector);

    if (element == null) {
        return false;
    }

    return element.isDisplayed();
}
 
Example 12
Project: xtf   File: DriverUtil.java   View Source Code Vote up 5 votes
public static boolean elementsPresent(WebDriver driver, By... elements) {
	try {
		for (By element : elements) {
			WebElement webElement = driver.findElement(element);
			if (!webElement.isDisplayed()) {
				return false;
			}
		}
		return true;
	} catch (NoSuchElementException | StaleElementReferenceException x) {
		return false;
	}
}
 
Example 13
Project: POM_HYBRID_FRAMEOWRK   File: WebUtilities.java   View Source Code Vote up 5 votes
/**
 * Checks if is element present.
 *
 * @param driver the driver
 * @param element the element
 * @param logger the logger
 * @return true, if is element present
 */
public static boolean isElementPresent(WebDriver driver, WebElement element, ExtentTest logger) {
	boolean elementPresent = false;

	try {
		if (element.isDisplayed()) {
			elementPresent = true;
			logger.log(LogStatus.INFO, "WebElement is visible");
		}
	} catch (Exception e) {
		logger.log(LogStatus.ERROR, "WebElement is not present...<br></br>" + e.getStackTrace());
		e.printStackTrace();
	}
	return elementPresent;
}
 
Example 14
Project: Actitime-Framework   File: HelperManager.java   View Source Code Vote up 5 votes
/**
 * This method makes the driver scroll to the specified webelement in
 * browser
 **/
public static boolean scrollTo(WebElement wb, WebDriver driver) {
	try {
		JavascriptExecutor je = (JavascriptExecutor) driver;
		je.executeScript("arguments[0].scrollIntoView(true);", wb);

	} catch (Exception e) {
		e.printStackTrace();
	}
	return wb.isDisplayed();
}
 
Example 15
Project: kheera   File: AbstractPage.java   View Source Code Vote up 4 votes
@Override
public boolean checkElementExists(WebElement w) throws Exception{
	Assert.assertTrue(w.isDisplayed(), w.toString() + " is visible");
	return w.isDisplayed();
}
 
Example 16
Project: tmply   File: TmplyPage.java   View Source Code Vote up 4 votes
public boolean isBucketNameInputPresent()
{
	WebElement bucketNameInput = getBucketNameInput();
	return bucketNameInput.isDisplayed();
}
 
Example 17
Project: bromium   File: ClickClassByText.java   View Source Code Vote up 4 votes
private boolean elementTextIsEqualToAndIsDisplayed(WebElement webElement) {
    boolean textIsCorrect = webElement.getAttribute(INNER_HTML).trim().equals(text);
    boolean elementIsDisplayed = webElement.isDisplayed();
    return textIsCorrect && elementIsDisplayed;
}
 
Example 18
Project: Selenium-Foundation   File: Coordinators.java   View Source Code Vote up 2 votes
/**
 * Return a visibility-filtered element reference
 * 
 * @param element element whose visibility is in question
 * @return specified element reference; 'null' if element is hidden
 */
private static WebElement elementIfVisible(WebElement element) {
    return element.isDisplayed() ? element : null;
}