List of usage examples for org.openqa.selenium WebElement isDisplayed
boolean isDisplayed();
From source file:com.ibm.watson.app.qaclassifier.selenium.MenuIT.java
License:Open Source License
@Ignore @Test/*from w ww. j a v a 2 s. co m*/ public void clickMenuIconThenAwayFromMenuIconHidesMenuList() { WebElement menuIconContainer = driver.findElement(By.id("menuIconContainerDesktop")); WebElement menuIconImg = menuIconContainer .findElement(By.xpath(".//span[contains(concat(' ', @class, ' '), ' menuIconImg ')]")); // Clicking away from the menu icon should also close the menu menuIconImg.click(); WebElement menuList = driver.findElement(By.tagName("menu-list")); assertTrue("After clicking the menu icon, the menu list is visible", menuList.isDisplayed()); Actions action = new Actions(driver); action.moveToElement(driver.findElement(By.tagName("body")), 0, 0); action.click().build().perform(); assertFalse("After clicking outside the menu icon, the menu list is gone", menuList.isDisplayed()); }
From source file:com.ibm.watson.app.qaclassifier.selenium.MenuIT.java
License:Open Source License
@Test public void clickingOnMenuListItemShowsOverlay() { WebElement menuIconContainer = driver.findElement(By.id("menuIconContainerDesktop")); WebElement menuIconImg = menuIconContainer .findElement(By.xpath(".//span[contains(concat(' ', @class, ' '), ' menuIconImg ')]")); // Validate that the menu list has options menuIconImg.click();/* ww w . j ava 2 s.com*/ WebElement menuList = driver.findElement(By.className("menu-list")); assertTrue("After clicking the menu icon, the menu list is visible", menuList.isDisplayed()); List<WebElement> menuOptions = menuList.findElements(By.xpath(".//ul/li")); // The first item should be home, which is hidden on Desktop, so skip it and do the second one WebElement firstMenuOption = menuOptions.get(2); String firstMenuOptionText = firstMenuOption.getText(); firstMenuOption.click(); assertTrue("Clicking on a menu option keeps the menu list open", menuList.isDisplayed()); WebElement menuOverlay = driver.findElement(By.id("menuOverlay")); WebElement menuOverlayHeading = menuOverlay.findElement(By.xpath(".//div[@class='header']/h2")); assertThat("The menu list option contains the same text as the menu overlay heading", firstMenuOptionText, is(menuOverlayHeading.getText())); WebElement menuOverlayContent = menuOverlay.findElement(By.id("menuContent")); assertTrue("The menu overlay contains some text content for the selected menu option", menuOverlayContent.getText().length() > 0); }
From source file:com.ibm.watson.app.qaclassifier.selenium.MenuMobileIT.java
License:Open Source License
@Test public void clickMenuIconShowsMenuOnMobile() { WebElement menuIconImg = driver.findElement(By.className("menuIconImg")); WebElement menuList = driver.findElement(By.className("menu-list")); // Click the menu icon, it should show the menu list menuIconImg.click();/*from w ww.ja v a 2 s.c om*/ assertTrue("After clicking on the menu icon, the menu list is shown", menuList.isDisplayed()); }
From source file:com.ibm.watson.app.qaclassifier.selenium.MenuMobileIT.java
License:Open Source License
@Test public void clickOnMenuOptionShowsContent() { WebElement menuIconImg = driver.findElement(By.className("menuIconImg")); WebElement menuList = driver.findElement(By.className("menu-list")); WebElement menuContent = driver.findElement(By.className("menu-content")); // Click the menu icon, it should show the menu list menuIconImg.click();// w w w . j a v a 2 s . c om //Get list of menu options List<WebElement> menuOptions = menuList.findElements(By.xpath(".//ul/li")); WebElement firstMenuOption = menuOptions.get(2); // Get content of "About" option that has content firstMenuOption.click(); new WebDriverWait(driver, 1).until(ExpectedConditions.visibilityOf(menuContent)); assertTrue("After clicking on the menu option, the menu option content is displayed", menuContent.isDisplayed()); }
From source file:com.ibm.watson.app.qaclassifier.selenium.MenuMobileIT.java
License:Open Source License
@Test public void clickOnMenuOptionRedirectsPage() throws InterruptedException { WebElement menuIconImg = driver.findElement(By.className("menuIconImg")); WebElement menuList = driver.findElement(By.className("menu-list")); assertTrue("Menu Icon is displayed", menuIconImg.isDisplayed()); // Click the menu icon, it should show the menu list menuIconImg.click();//from w ww. j a v a 2s . c om // Unclear exactly why this is required. // Without this delay the findElements call might return less than the expected number of elements, // or some of the elements might not have any text. Thread.sleep(1000); //Get list of menu options List<WebElement> menuOptions = menuList.findElements(By.xpath(".//ul/li")); assertThat("Expect four menu options", menuOptions, hasSize(4)); int menuIndex = 1; WebElement documentationOption = menuOptions.get(menuIndex); // "Documentation" option that will redirect to different page assertThat("Unexpected text for item at position " + menuIndex, documentationOption.getText(), is("Documentation")); documentationOption.click(); //New tab with documentation is opened CommonFunctions.switchTabs(driver); assertThat("After clicking on the menu option, page is redirected", driver.getTitle(), is("Natural Language Classifier service documentation | Watson Developer Cloud")); driver.close(); }
From source file:com.ibm.watson.movieapp.dialog.fvt.webui.BaseUI.java
License:Open Source License
/** * isVisible - Checks whether the given locator matches a visible WebElement * @param locator The locator for the element * @return true if the element is found and visible */// www. j a v a 2 s . c o m public boolean isVisible(String locator) { boolean found = false; try { WebElement element = findElement(locator); if (element.isDisplayed()) { logger.info("INFO: Element " + locator + " found and is visible"); found = true; } } catch (NoSuchElementException err) { //Ignore } return found; }
From source file:com.itson.servicedesigncenter.SdcPages.java
License:Open Source License
public SdcPages setPortalLogin(String email, String Password) { this.setSaasUserNameTextField(email).setSaasUserPasswordTextField(Password).setLogInBTTN(); try {//from www .j av a 2 s .c o m browser.waitForClickableElement(By.id("EulaAcceptCheckbox")); WebElement eula = browser.findElementFast(By.id("EulaSubmitBtn")); this.setIAgreeEulaAcceptCheckbox().setEulaSubmitBtn(); } catch (Exception e) { /* * At this point we may have skipped past the EULA because we have logged in before * If this is the case we get a SkipException from the browser and we will test to make sure we * can see the Home Page, if not we raise an illegal state ie something bad happened. */ System.out.println("Eula not present, trying home page"); browser.log(Level.WARNING, "Eula not present, trying home page"); } WebElement home = browser.findElementFast(By.id("navigLinkToHome")); if (!home.isDisplayed()) { throw new IllegalStateException("Unable to get past Login Eula page"); } return this; }
From source file:com.jaeksoft.searchlib.crawler.web.spider.ClickCapture.java
License:Open Source License
private boolean locateAimgClickCapture(WebElement aElement) { if (!aElement.isDisplayed()) return false; String ahref = aElement.getAttribute("href"); List<WebElement> imgElements = aElement.findElements(By.cssSelector("img")); if (imgElements == null) return false; for (WebElement imgElement : imgElements) { if (!imgElement.isDisplayed()) continue; imgSrc = imgElement.getAttribute("src"); }// w w w. j a v a 2 s .co m anchorHref = ahref; return true; }
From source file:com.jaeksoft.searchlib.crawler.web.spider.ClickCapture.java
License:Open Source License
private boolean locateEmbedClickCapture(List<WebElement> embedElements) throws SearchLibException, IOException { if (embedElements == null) return false; for (WebElement embedElement : embedElements) { if (!embedElement.isDisplayed()) continue; embedSrc = embedElement.getAttribute("src"); String flashVars = embedElement.getAttribute("flashvars"); if (!StringUtils.isEmpty(flashVars)) { try { URI uri = new URI(embedSrc); flashVars = uri.getQuery(); } catch (URISyntaxException e) { Logging.warn(e);/*from w ww . j a va 2 s. c o m*/ } } String[] params = StringUtils.split(flashVars, '&'); Map<String, String> paramMap = new TreeMap<String, String>(); if (params != null) { for (String param : params) { String[] keyValue = StringUtils.split(param, '='); if (keyValue != null && keyValue.length == 2) paramMap.put(keyValue[0].toLowerCase(), URLDecoder.decode(keyValue[1], "UTF-8")); } } if (selector.flashVarsLink != null) anchorHref = paramMap.get(selector.flashVarsLink); return true; } return false; }
From source file:com.jaeksoft.searchlib.crawler.web.spider.ClickCapture.java
License:Open Source License
private boolean locateIFrame(BrowserDriver<?> browserDriver, List<WebElement> iFrameElements) throws SearchLibException, IOException { try {//from www. j a v a2 s .co m if (CollectionUtils.isEmpty(iFrameElements)) return false; for (WebElement frameWebElement : iFrameElements) { if (!frameWebElement.isDisplayed()) continue; browserDriver.switchToFrame(frameWebElement); if (locateElement(browserDriver, null)) return true; } return false; } finally { browserDriver.switchToMain(); } }