List of usage examples for org.openqa.selenium WebElement findElements
@Override List<WebElement> findElements(By by);
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 w w. j a va 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.MovieUI.java
License:Open Source License
/** * askQuestion//from w w w. ja v a 2 s . c om * @param question */ public void ask(BaseQuestion question) { BaseResponse resp = new BaseResponse.Builder().build(); //wait for chatbox to be enabled fluentWaitNotPresent(chatBoxDisabled); //collect conversation List<WebElement> preQuestCount = findElements(conversationsWeb); logger.info("INFO: Number of total questions asked in this conversations " + preQuestCount.size()); //ensure the chatbox exists fluentWaitVisible(chatBox); WebElement chatbox = findElement(chatBox); chatbox.click(); logger.info("INFO: Sending \"" + question.getText() + "\" to " + chatBox); chatbox.sendKeys(question.getText()); chatbox.submit(); //wait for thinking animation has completed fluentWaitNotPresent(watsonThinkAnimation); //collect questions and wait for new question to be added List<WebElement> postQuestCount = findElements(conversationsWeb); while (preQuestCount.size() >= postQuestCount.size()) { postQuestCount = findElements(conversationsWeb); } //General check to ensure that we are not waiting on any animations fluentWaitNotPresent(animationActive); logger.info("INFO: Number of total questions asked in this conversations " + postQuestCount.size()); //collect last question answer WebElement thisQuestion = postQuestCount.get(postQuestCount.size() - 1); List<WebElement> questPart = thisQuestion.findElements(By.cssSelector(questionParts)); //set response to the answer resp.setResponseText(questPart.get(1).getText()); //add response to question logger.info("INFO: Adding Response text to Question object"); question.setResponse(resp); //add any movies that are part of the response to question List<WebElement> movies = findElements(movieResponse); if (movies.size() > 0) { question.setMovies(movies); } }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ComboBoxValidatorSD.java
License:Open Source License
@Override public void validateSelectedItem(String expectedSelectedValue, TextValidationMechanism validationMechanism, int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ComboBox '" + uiObject.getDisplayName() + "'."); Assert.assertTrue(options.size() > 0, "Failed to find items in ComboBox '" + uiObject.getDisplayName() + "'. Found 0 items."); String optionTextValue;/*www. j av a 2s . c o m*/ boolean found = false; for (WebElement option : options) { optionTextValue = option.getText(); if (optionTextValue != null && option.isSelected() && matchTextValue(optionTextValue.trim(), expectedSelectedValue, validationMechanism)) { found = true; break; } } if (!found) { Assert.fail("Failed to find selected item '" + expectedSelectedValue + "' in ComboBox '" + uiObject.getDisplayName() + "'."); } }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ComboBoxValidatorSD.java
License:Open Source License
@Override public String getSelectedItem(int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ComboBox '" + uiObject.getDisplayName() + "'."); Assert.assertTrue(options.size() > 0, "Failed to find items in ComboBox '" + uiObject.getDisplayName() + "'. Found 0 items."); String optionTextValue;/*from w w w. j a va 2 s .c o m*/ for (WebElement option : options) { optionTextValue = option.getText(); if (optionTextValue != null && option.isSelected()) { return optionTextValue; } } return null; }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ComboBoxValidatorSD.java
License:Open Source License
@Override public List<String> getSelectedItems(int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ComboBox '" + uiObject.getDisplayName() + "'."); Assert.assertTrue(options.size() > 0, "Failed to find items in ComboBox '" + uiObject.getDisplayName() + "'. Found 0 items."); List<String> selectedItems = new LinkedList<String>(); String optionTextValue;/*from w w w . j a v a2 s .c o m*/ for (WebElement option : options) { optionTextValue = option.getText(); if (optionTextValue != null && option.isSelected()) { selectedItems.add(optionTextValue); } } return selectedItems; }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ComboBoxValidatorSD.java
License:Open Source License
@Override public void selectFirstItem(int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); selectElement.click();/*from www . j a v a2s.com*/ List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ComboBox '" + uiObject.getDisplayName() + "'."); Assert.assertTrue(options.size() > 0, "Failed to find items in ComboBox '" + uiObject.getDisplayName() + "'. Found 0 items."); options.get(0).click(); }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ComboBoxValidatorSD.java
License:Open Source License
@Override public void selectLastItem(int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); selectElement.click();/*w w w .j av a2 s . co m*/ List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ComboBox '" + uiObject.getDisplayName() + "'."); Assert.assertTrue(options.size() > 0, "Failed to find items in ComboBox '" + uiObject.getDisplayName() + "'. Found 0 items."); options.get(options.size() - 1).click(); }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ComboBoxValidatorSD.java
License:Open Source License
@Override public void selectItem(String itemName, int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); selectElement.click();/*from w w w . ja v a2s . co m*/ List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ComboBox '" + uiObject.getDisplayName() + "'."); String optionTextValue; boolean found = false; for (WebElement option : options) { optionTextValue = option.getText(); if (optionTextValue != null && itemName.equals(optionTextValue.trim())) { option.click(); found = true; break; } } if (!found) { Assert.fail("Failed to find item '" + itemName + "' in ComboBox '" + uiObject.getDisplayName() + "'."); } }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ComboBoxValidatorSD.java
License:Open Source License
@Override public void validateItemsPresent(ItemList<String> items, int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ComboBox '" + uiObject.getDisplayName() + "'."); Assert.assertTrue(options.size() > 0, "Failed to find items in ComboBox '" + uiObject.getDisplayName() + "'. Found 0 items."); String optionTextValue;// ww w. j av a 2 s . c o m for (String item : items.getItems()) { boolean found = false; for (WebElement option : options) { optionTextValue = option.getText(); if (optionTextValue != null && matchTextValue(optionTextValue.trim(), item, TextValidationMechanism.exactMatchWithExpectedValue)) { found = true; break; } } if (!found) { Assert.fail("Failed to find item '" + item + "' in ComboBox '" + uiObject.getDisplayName() + "'."); } } }
From source file:com.induscorp.prime.testing.ui.standard.domobj.ComboBoxValidatorSD.java
License:Open Source License
@Override public void validateItemsNotPresent(ItemList<String> items, int numRetries) { WebElement selectElement = domObjValidator.findElement(numRetries); List<WebElement> options = selectElement.findElements(By.xpath("./option")); Assert.assertNotNull(options, "Failed to find items for ComboBox '" + uiObject.getDisplayName() + "'."); Assert.assertTrue(options.size() > 0, "Failed to find items in ComboBox '" + uiObject.getDisplayName() + "'. Found 0 items."); String optionTextValue;/* w ww . j ava 2s.c o m*/ for (String item : items.getItems()) { boolean found = false; for (WebElement option : options) { optionTextValue = option.getText(); if (optionTextValue != null && matchTextValue(optionTextValue.trim(), item, TextValidationMechanism.exactMatchWithExpectedValue)) { found = true; break; } } if (found) { Assert.fail("Item '" + item + "' is present in ComboBox '" + uiObject.getDisplayName() + "'."); } } }