List of usage examples for org.openqa.selenium WebElement isDisplayed
boolean isDisplayed();
From source file:com.java.AppTestType_18_11_2015.java
public void NONZEROCOUNT(WebDriver driver) { try {//from ww w. ja v a 2 s . c om WebElement lots = driver.findElement(By.id("e1NumFound")); WebElement auctions = driver.findElement(By.id("e1AuctionsFound")); WebElement events = driver.findElement(By.id("e1ResultsFound")); String count = ""; //to get text of lots or auctions or events count if (lots.isDisplayed()) { count = driver.findElement(By.id("e1NumFound")).getText(); } else if (auctions.isDisplayed()) { count = driver.findElement(By.id("e1AuctionsFound")).getText(); } else if (events.isDisplayed()) { count = driver.findElement(By.id("e1ResultsFound")).getText(); } String convertcount = count.replace(",", ""); int sitemapcount = Integer.parseInt(convertcount); System.out.println("count is :" + sitemapcount); if (sitemapcount > 0) resultDetails.setFlag(true); else { resultDetails.setErrorMessage("Zero lots Found"); System.out.println("Non Zero Count"); resultDetails.setFlag(false); } } catch (Exception e) { resultDetails.setErrorMessage("Zero lots Found"); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void COMPARE(WebDriver driver, String action) { List<WebElement> results = driver.findElements(By.id("results")); for (WebElement rel : results) { rel.getText();//from w ww . j a va2 s .c om //System.out.println(rel.getText()); WebElement compare = driver.findElement(By.className("compare")); keywords comparecheck = keywords.valueOf(action.toUpperCase()); switch (comparecheck) { case fposition: try { if (compare.isDisplayed()) { driver.findElement(By.cssSelector("input.selectoff")).click(); } } catch (Exception e) { } break; case sposition: break; case tposition: break; } } }
From source file:com.lazerycode.ebselen.EbselenCommands.java
License:Apache License
/** * Open site homepage and check that it has loaded correctly. * This will set the currently selected site to the value of page * * @param homepageURL URL of the homepage * @param homePageElement If homePageElement is not null kill tests if it does not exist *//*from www .j av a 2 s . com*/ public void openHomepage(String homepageURL, WebElement homePageElement) throws Exception { driver.get(homepageURL); if (homePageElement != null) { if (!homePageElement.isDisplayed()) { throw new HomepageNotLoadedException(); } } }
From source file:com.liferay.cucumber.selenium.BaseWebDriverImpl.java
License:Open Source License
@Override public boolean isVisible(String locator) { WebElement webElement = getWebElement(locator, "1"); scrollWebElementIntoView(webElement); return webElement.isDisplayed(); }
From source file:com.liferay.cucumber.selenium.WebDriverHelper.java
License:Open Source License
public static void executeJavaScriptEvent(WebDriver webDriver, String locator, String eventType, String event) { WebElement webElement = getWebElement(webDriver, locator); WrapsDriver wrapsDriver = (WrapsDriver) webElement; WebDriver wrappedWebDriver = wrapsDriver.getWrappedDriver(); JavascriptExecutor javascriptExecutor = (JavascriptExecutor) wrappedWebDriver; if (!webElement.isDisplayed()) { scrollWebElementIntoView(webDriver, webElement); }//from ww w. jav a 2 s . co m StringBuilder sb = new StringBuilder(6); sb.append("var element = arguments[0];"); sb.append("var event = document.createEvent('"); sb.append(eventType); sb.append("');event.initEvent('"); sb.append(event); sb.append("', true, false);element.dispatchEvent(event);"); javascriptExecutor.executeScript(sb.toString(), webElement); }
From source file:com.liferay.cucumber.selenium.WebDriverHelper.java
License:Open Source License
protected static void scrollWebElementIntoView(WebDriver webDriver, WebElement webElement) { if (!webElement.isDisplayed() || isObscured(webDriver, webElement)) { WrapsDriver wrapsDriver = (WrapsDriver) webElement; WebDriver wrappedWebDriver = wrapsDriver.getWrappedDriver(); JavascriptExecutor javascriptExecutor = (JavascriptExecutor) wrappedWebDriver; javascriptExecutor.executeScript("arguments[0].scrollIntoView(false);", webElement); }/*from w w w. j a v a 2 s . co m*/ }
From source file:com.liferay.faces.portal.test.showcase.inputrichtext.InputRichTextTester.java
License:Open Source License
private static boolean isCheckboxDisplayedAndEnabled(BrowserDriver browserDriver, String checkboxType) { String checkboxXpath = "//input[contains(@id,':{0}Checkbox')]".replace("{0}", checkboxType); WebElement checkbox = null; List<WebElement> webElements = browserDriver.findElementsByXpath(checkboxXpath); if (!webElements.isEmpty()) { checkbox = webElements.get(0);//from w w w . j ava 2s .c o m } return (checkbox != null) && checkbox.isDisplayed() && checkbox.isEnabled(); }
From source file:com.liferay.faces.test.showcase.facesrequestcontext.FacesRequestContextGeneralTester.java
License:Open Source License
@Test public void runFacesRequestContextGeneralTest() throws Exception { Browser browser = Browser.getInstance(); navigateToUseCase(browser, "util", "FacesRequestContext", "general"); // Test that clicking the "Show Modal" button shows the modal. browser.click("(//*[contains(@value,'Show Modal')])[1]"); browser.waitForElementVisible(submitButton1Xpath); String modalDialogXpath = "//div[contains(@class,'modal-dialog')]"; SeleniumAssert.assertElementVisible(browser, modalDialogXpath); // Test that the modal is still visible (and shows an error message) when an empty value is submitted. browser.clickAndWaitForAjaxRerender(submitButton1Xpath); SeleniumAssert.assertElementVisible(browser, modalDialogXpath); SeleniumAssert.assertElementTextVisible(browser, error1Xpath, "Email: Validation Error: Value is required."); // Test that the modal is still visible (and shows an error message) when an invalid value is submitted. String emailAddressInputTextXpath = "(//input[contains(@id,':text')])[1]"; browser.sendKeys(emailAddressInputTextXpath, "HelloWorldcom"); browser.clickAndWaitForAjaxRerender(submitButton1Xpath); SeleniumAssert.assertElementVisible(browser, modalDialogXpath); SeleniumAssert.assertElementTextVisible(browser, error1Xpath, "Invalid E-Mail Address"); // Test that a valid value submits successfully and the modal disappears. browser.clear(emailAddressInputTextXpath); browser.sendKeys(emailAddressInputTextXpath, "hello@world.com"); WebElement submitButton1 = browser.findElementByXpath(submitButton1Xpath); submitButton1.click();/*from w ww. j av a 2 s . com*/ browser.waitUntil(ExpectedConditions.stalenessOf(submitButton1)); browser.waitForElementPresent(submitButton1Xpath); WebElement modalElement = browser.findElementByXpath(modalDialogXpath); Assert.assertTrue("Element " + modalDialogXpath + " is displayed.", !modalElement.isDisplayed()); }
From source file:com.mediamelon.UserActions.java
void addAccount(WebDriver driver, List<String> formData) { //Verify if the user is logged in as Super User to create a new account. //If not, display message and return //Verify if the user is logged in String pageTitle = driver.getTitle(); Assert.assertEquals(pageTitle, "MediaMelon - Home"); String fullName = driver.findElement(By.xpath("//div[@class='row data']/div/div[1]/p[2]")).getText(); String role = driver.findElement(By.xpath("//div[@class='row data']/div/div[3]/p[2]")).getText(); if (fullName.equalsIgnoreCase("Super User") && role.equalsIgnoreCase("admin")) { System.out.println("List of Accounts is displayed"); //expand the settings menu option and click on Account Management List<WebElement> dropDownOptions = driver.findElements(By.className("dropdown-toggle")); dropDownOptions.get(0).click();/* ww w . j ava 2 s .c om*/ WebElement accountManagement = driver.findElement(By.cssSelector(".dropdown-menu.dropdown-admin")); Assert.assertTrue(accountManagement.isDisplayed()); accountManagement.findElement(By.linkText("Account Management")).click(); Assert.assertEquals(driver.getTitle(), "List of Accounts"); WebElement accountsTable = driver.findElement(By.xpath("//div[@class='row well']/table")); Assert.assertTrue(accountsTable.isDisplayed()); WebElement addAccountBtn = driver.findElement(By.cssSelector(".btn.btn-primary")); System.out.println("Clicking on Add a new account button"); Assert.assertEquals(addAccountBtn.getText(), "Add a new Account"); addAccountBtn.click(); //Fill account add form WebElement accountForm = driver.findElement(By.tagName("form")); Assert.assertTrue(accountForm.isDisplayed()); System.out.println(accountForm.getAttribute("action")); accountForm.findElement(By.id("companyName")).sendKeys(formData.get(0)); accountForm.findElement(By.id("companyWebsite")).sendKeys(formData.get(1)); accountForm.findElement(By.id("adminName")).sendKeys(formData.get(2)); accountForm.findElement(By.id("adminEmail")).sendKeys(formData.get(3)); Select licenseType = new Select(driver.findElement(By.id("licenseType"))); licenseType.selectByVisibleText(formData.get(4)); Select services = new Select(driver.findElement(By.id("services"))); String requiredServices = formData.get(5); String multipleSel[] = formData.get(5).split(","); if (requiredServices.equalsIgnoreCase("All")) { services.selectByIndex(0); services.selectByIndex(1); services.selectByIndex(2); } else if (multipleSel.length > 1) { for (int i = 0; i < multipleSel.length; i++) services.selectByVisibleText(multipleSel[i]); } else services.selectByVisibleText(requiredServices); accountForm.findElement(By.id("companyName")).sendKeys(formData.get(5)); //submit the form System.out.println("Submitting the form"); accountForm.findElement(By.cssSelector("button[value='submit']")).click(); System.out.println("clicked on submit button"); accountsTable = driver.findElement(By.cssSelector("table.table-striped.table-hover.table-bordered")); Assert.assertTrue(accountsTable.isDisplayed()); System.out.println("form submitted sucessfully"); //Verify the presence of newly created account in the list of accounts System.out.println("Verifying if the newly created account is present in the list"); String tableData = accountsTable.getText(); System.out.println("Table Data: " + tableData); //findElement(By.xpath(".//*[@class='studyResultsId']/div/table/tbody/tr/td")).getText(); //Retrieving the data from the Td of table in to a string if (tableData.contains(formData.get(5))) { System.out.println("contains newly created account"); } else { System.out.println("does not contains newly created account"); } } else System.out.println("User not authorized to create an account"); }
From source file:com.mgmtp.jfunk.web.step.Check4Element.java
License:Apache License
/** * @throws StepException// ww w.j a va2s . c om * if element specified by {@link By} object in the constructor cannot be found */ @Override public void execute() throws StepException { if (mustExist) { log.info("Checking if " + this + " is present"); } else { log.info("Checking that " + this + " does not exist"); } List<WebElement> webElements = getWebDriver().findElements(by); if (webElements.isEmpty()) { if (mustExist) { throw new StepException("Could not find any matching element"); } } else { // webElements is not empty if (!mustExist) { throw new StepException("Matching element could be found although mustExist=false"); } /* * If the search using the By object does find more than one matching element we are looping through all elements if * we find at least one which matches the criteria below. If not, an exception is thrown. */ for (WebElement element : webElements) { if (element.isDisplayed()) { if (element.isEnabled()) { if (!mustExist) { throw new StepException("Matching element could be found although mustExist=false"); } return; } } } throw new StepException("All elements matching by=" + by + " were either invisible or disabled"); } }