List of usage examples for org.openqa.selenium WebDriver findElements
@Override List<WebElement> findElements(By by);
From source file:com.java.AppTestType_18_11_2015.java
public void VERIFYNOT(WebDriver driver, String fieldText, String value) { //To verify that the locator doesn't exist //FieldText---Locator //value----Time in ms //Give lesser Time like 2000,or else the execution will wait that much time try {/*from www.j a v a 2 s . co m*/ String f = fieldText; String time = value; String locatorType = f.substring(0, 3); String locatorValue = f.substring(3, f.length()); int timevalue = Integer.parseInt(time); driver.manage().timeouts().implicitlyWait(timevalue, TimeUnit.MILLISECONDS); if (locatorType.equalsIgnoreCase("XPH")) { if (driver.findElements(By.xpath(locatorValue)).size() == 0) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("LNK")) { if (driver.findElements(By.linkText(locatorValue)).size() == 0) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("IDI") || locatorType.equalsIgnoreCase("TXT")) { if (driver.findElements(By.id(locatorValue)).size() == 0) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("MSG")) { int j = 0; int t = timevalue / 1000; for (int i = 0; i < t; i++) { if (driver.findElements(By.xpath("//*[contains(text(),'" + locatorValue + "')]")).size() == 0) { j = 1; break; } Thread.sleep(1000); } if (j == 1) resultDetails.setFlag(true); } else if (locatorType.equalsIgnoreCase("PLK")) { if (driver.findElements(By.partialLinkText(locatorValue)).size() == 0) resultDetails.setFlag(true); } } catch (Exception e) { e.printStackTrace(); resultDetails.setErrorMessage("Element is Present"); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void ADDINGTOWATCHLIST(WebDriver driver) { driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); try {//from w w w .j a v a 2 s . c om if (driver.findElements(By.xpath( "(//i[@class='fa fa-binoculars fa-watchstack jswatchtitle' and contains(@data-original-title,'Click to remove from')])[1]")) .size() > 0) System.out.println("already there are some lots in watchlist section"); else driver.findElement(By.xpath( "(//i[@class='fa fa-binoculars fa-watchstack jswatchtitle' and contains(@data-original-title,'Click to add to')])[1]")) .click(); resultDetails.setFlag(true); } catch (Exception e) { e.printStackTrace(); resultDetails.setErrorMessage("Element is checked"); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void SEARCHLOTINAMP(WebDriver driver, String fieldText, String value) { String EQID = null;//from www . j a v a 2 s.c o m try { String AMPUrl = fieldText; String AMPPage = value.toUpperCase(); driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); switch (AMPPage) { case "LOTS2": EQID = FINDLOTID(driver, AMPUrl); Thread.sleep(4000); driver.findElement(By.linkText("Lots")).click(); Thread.sleep(2000); driver.findElement(By.xpath("//*[text()='Lot Number:']/../td[2]/input")).sendKeys(EQID); driver.findElement(By.xpath("//input[@name='find_button']")).click(); if (driver .findElement( By.xpath("//*[@id='renderView']/table[2]/tbody/tr[1]/td[2]/table/tbody/tr[1]/td/a")) .getText().contains(EQID)) resultDetails.setFlag(true); break; case "HOME": case "LOTS": EQID = FINDLOTID(driver, AMPUrl); Thread.sleep(4000); driver.findElement(By.linkText(value)).click(); Thread.sleep(2000); driver.findElement(By.xpath("//*[@name='search_string']")).sendKeys(EQID); driver.findElement(By.xpath("//button[text()='Search']")).click(); if (driver.findElement(By.xpath("//td[@class='listdatabold' and text()='Lot Number:']/../td[4]")) .getText().equalsIgnoreCase(EQID)) resultDetails.setFlag(true); break; case "VENUE": AMPLOGIN(driver, AMPUrl); driver.findElement(By.linkText("Lots")).click(); Thread.sleep(4000); new Select(driver.findElement(By.xpath("//select[@name='venueID']"))) .selectByVisibleText("EquipmentOne"); driver.findElement(By.xpath("//input[@name='find_button']")).click(); int size = driver.findElements(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).size(); for (int i = 1; i <= size; i++) { if (driver.findElement(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).getText() .contains("(EQ")) resultDetails.setFlag(true); else { resultDetails.setFlag(false); break; } } break; case "STATUS": AMPLOGIN(driver, AMPUrl); driver.findElement(By.linkText("Lots")).click(); Thread.sleep(4000); new Select(driver.findElement(By.xpath("//select[@name='venueID']"))) .selectByVisibleText("EquipmentOne"); new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']"))) .selectByVisibleText("Approved"); driver.findElement(By.xpath("//input[@name='find_button']")).click(); size = driver.findElements(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).size(); for (int i = 1; i < size * 2; i++) { if (driver.findElement(By .xpath("//*[@id='renderView']/table[2]/tbody/tr[" + i + "]/td[1]/table/tbody/tr[3]/td")) .getText().equalsIgnoreCase("Approved")) { resultDetails.setFlag(true); i++;//because, there is one more empry row in table after each and every lot row. So we are skipping that empty row } else { resultDetails.setFlag(false); break; } } break; case "WITHOUTBUYITNOW": AMPLOGIN(driver, AMPUrl); driver.findElement(By.linkText("Lots")).click(); Thread.sleep(4000); new Select(driver.findElement(By.xpath("//select[@name='venueID']"))) .selectByVisibleText("EquipmentOne"); new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']"))) .selectByVisibleText("Approved"); System.out.println("is buy it now selected currently: " + driver.findElement(By.xpath("(//*[@name='offerSrhBuyItNowAllowed'])[2]")).isSelected()); if (driver.findElement(By.xpath("(//*[@name='offerSrhBuyItNowAllowed'])[2]")).isSelected()) driver.findElement(By.xpath("(//*[@name='offerSrhBuyItNowAllowed'])[2]")).click(); driver.findElement(By.xpath("//input[@name='find_button']")).click(); size = driver.findElements(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).size(); driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS); for (int i = 1; i < size * 2; i++) { if (driver.findElements(By.xpath("//*[@id='renderView']/table[2]/tbody/tr[" + i + "]/td[1]/table/tbody/tr[2]/td/img[contains(@src,'buyitnow')]")).size() == 0) { resultDetails.setFlag(true); i++; //because, there is one more empry row in table after each and every lot row. So we are skipping that empty row } else { System.out.println("Lot displayed with BIN"); resultDetails.setFlag(false); break; } } driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); break; case "WITHBUYITNOW": AMPLOGIN(driver, AMPUrl); driver.findElement(By.linkText("Lots")).click(); Thread.sleep(4000); new Select(driver.findElement(By.xpath("//select[@name='venueID']"))) .selectByVisibleText("EquipmentOne"); new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']"))) .selectByVisibleText("Approved"); if (driver.findElement(By.xpath("//*[@name='offerSrhBuyItNowAllowed']")).isSelected()) driver.findElement(By.xpath("//*[@name='offerSrhBuyItNowAllowed']")).click(); driver.findElement(By.xpath("//input[@name='find_button']")).click(); size = driver.findElements(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).size(); for (int i = 1; i < size * 2; i++) { if (driver.findElements(By.xpath("//*[@id='renderView']/table[2]/tbody/tr[" + i + "]/td[1]/table/tbody/tr[2]/td/img[contains(@src,'buyitnow')]")).size() == 1) { resultDetails.setFlag(true); i++; //because, there is one more empry row in table after each and every lot row. So we are skipping that empty row } else { System.out.println("Lot displayed without BIN"); resultDetails.setFlag(false); break; } } break; } } catch (Exception e) { System.out.println(e); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void SEARCHLOTINEQWITHEQID(WebDriver driver, String pagename) { driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); try {// w ww . j av a2s . co m Thread.sleep(5000); if (pagename.equalsIgnoreCase("LotDetailsPage")) eqid_1 = driver.findElement(By.xpath("//*[contains(text(),'Lot ID:')]/span")).getText(); else if (pagename.equalsIgnoreCase("SEARCHRESULTPAGE")) eqid_1 = driver.findElement(By.xpath("(//div[@class='rgbold jsLotID myone-black'])[4]")).getText(); else if (pagename.equalsIgnoreCase("HOMEPAGE")) { eqid_1 = driver.findElement(By.xpath("(//div[@class='rgbold jsLotID myone-black'])[4]")).getText(); //moving to home page driver.findElement(By.xpath("//a/img[@class='logo-img img-responsive']")).click(); } else if (pagename.equalsIgnoreCase("MYONEPAGE")) { eqid_1 = driver.findElement(By.xpath("(//div[@class='rgbold jsLotID myone-black'])[4]")).getText(); //moving to home page driver.findElement(By.xpath("(//a[contains(text(),'MyONE')])[2]")).click(); } Thread.sleep(5000); //searching with above lot id driver.findElement(By.id("search")).sendKeys(eqid_1); driver.findElement(By.xpath("//*[@id='main_search']/button")).click(); WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.presenceOfElementLocated( By.xpath("(//div[@class='search-tags']/ul/li[text()='" + eqid_1 + "'])[2]"))); String actual_eqid = driver.findElement(By.xpath("(//div[@class='rgbold jsLotID myone-black'])[4]")) .getText(); //checking the size of search result elements, first 2 are invisible elements and each lot is having 2 more elements, so size should not exceed 4 int size = driver.findElements(By.xpath("(//div[@class='rgbold jsLotID myone-black'])")).size(); System.out.println("suman999999999999999999999999999999999999999999999999: " + size); if (size == 4 && actual_eqid.equalsIgnoreCase(eqid_1)) resultDetails.setFlag(true); } catch (Exception e) { System.out.println(e); resultDetails.setFlag(false); } }
From source file:com.java.AppTestType_18_11_2015.java
public void AssetNation(WebDriver driver) { try {/*from w w w.jav a 2 s . c om*/ // Actions to be performed on failure if (driver.getPageSource().contains("500 Internal server error")) { driver.navigate().refresh(); } int userid = driver.findElements(By.id("iduser")).size(); int logoutlink = driver.findElements(By.linkText("Logout")).size(); if (userid > 0) { SIGNOUT(driver); System.out.println("Clicked on Signout after Fail"); } else if (logoutlink > 0) { AMPLOGOUT(driver); } } catch (Exception e) { System.out.println(e); } }
From source file:com.java.AppTestType_18_11_2015.java
public void WAITFORTHIS_2(WebDriver driver, String fieldText, String value) throws Exception { int i = 0;/*www .j a va 2s .c om*/ driver.manage().timeouts().implicitlyWait(20, TimeUnit.MILLISECONDS); String f = fieldText; String val = value; String locatorType = f.substring(0, 3); String locatorValue = f.substring(3, f.length()); if (locatorType.equalsIgnoreCase("XPH")) { if (driver.findElements(By.xpath(locatorValue)).size() > 0) i = 1; } else if (locatorType.equalsIgnoreCase("LNK")) { if (driver.findElements(By.linkText(locatorValue)).size() > 0) i = 1; } if (i == 0) { resultDetails.setErrorMessage(fieldText + "Locator Not Found"); throw new Exception(); } }
From source file:com.liferay.cucumber.selenium.WebDriverHelper.java
License:Open Source License
protected static List<WebElement> getWebElements(WebDriver webDriver, String locator, String timeout) { if (timeout != null) { setTimeoutImplicit(webDriver, timeout); }//from w ww . j a va2s . c om try { List<WebElement> webElements = new ArrayList<>(); for (WebElement webElement : webDriver.findElements(getBy(locator))) { webElements.add(new RetryWebElementImpl(locator, webElement)); } return webElements; } finally { if (timeout != null) { setDefaultTimeoutImplicit(webDriver); } } }
From source file:com.liferay.faces.test.selenium.browser.internal.BrowserDriverImpl.java
License:Open Source License
@Override public List<WebElement> findElementsByXpath(String elementXpath) { WebDriver webDriver = getWebDriver(); return webDriver.findElements(By.xpath(elementXpath)); }
From source file:com.liferay.faces.test.selenium.expectedconditions.ElementEnabled.java
License:Open Source License
@Override public WebElement apply(WebDriver webDriver) { WebElement webElement = null;//from ww w .j ava2 s . co m try { List<WebElement> webElements = webDriver.findElements(By.xpath(elementXpath)); if (!webElements.isEmpty() && webElements.get(0).isEnabled()) { webElement = webElements.get(0); } } catch (StaleElementReferenceException e) { // Do nothing. } return webElement; }
From source file:com.liferay.faces.test.util.TesterBase.java
License:Open Source License
public boolean isThere(WebDriver browser, String xpath) { boolean isThere = false; int count = 0; count = browser.findElements(By.xpath(xpath)).size(); if (count == 0) { isThere = false;/*ww w.ja v a2s. c o m*/ } if (count > 0) { isThere = true; } if (count > 1) { logger.log(Level.WARNING, "The method 'isThere(xpath)' found " + count + " matches using xpath = " + xpath + " ... the word 'is' implies singluar, or 1, not " + count); } return isThere; }