List of usage examples for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated
public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator)
From source file:functional.org.ojbc.web.portal.controllers.TestBase.java
License:RPL License
public static void waitForElement(By by, WebDriver driver) { WebDriverWait webDriverWait = new WebDriverWait(driver, WAIT_IN_SECONDS); try {/*from w w w .ja va 2 s . c om*/ webDriverWait.until(ExpectedConditions.presenceOfElementLocated(by)); } catch (Exception ex) { } }
From source file:functions.CommonCalls.java
public boolean ExplicitWait(String webelement) { try {/* ww w. j a va 2s. c om*/ WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.presenceOfElementLocated(By.id("webelement"))); return true; } catch (Exception e) { System.out.print(e); return false; } }
From source file:gheckodrivertest.BestJobsFirstPage.java
public static void main(String[] args) // TODO code application logic here { try {/*from w ww.j a v a 2 s . c o m*/ //System.setProperty("webdriver.gecko.driver", "D:\\Documentatie\\Selenium\\geckodriver\\geckodriver.exe"); System.setProperty("webdriver.gecko.driver", "D:\\gdrwrapper.bat"); System.setProperty("webdriver.gecko.logfile", "D:\\geckodriver.log"); WebDriver driver = new FirefoxDriver(); DesiredCapabilities capabilities = DesiredCapabilities.firefox(); LoggingPreferences logPrefs = new LoggingPreferences(); logPrefs.enable(LogType.BROWSER, Level.ALL); logPrefs.enable(LogType.CLIENT, Level.ALL); logPrefs.enable(LogType.DRIVER, Level.ALL); logPrefs.enable(LogType.SERVER, Level.ALL); logPrefs.enable(LogType.PERFORMANCE, Level.ALL); capabilities.setCapability(CapabilityType.LOGGING_PREFS, logPrefs); driver.get("http:\\bestjobs.eu"); WebElement btnEnter = driver.findElement(By.xpath("html/body/div[1]/div/div/div/div/div[2]/a/button")); btnEnter.click(); //driver.manage().timeouts().wait(30); System.out.println(driver.getTitle()); /** * <li * class="sign-up-switch amplitude" data - key = "sign_up_email_started" * > <a * href = "/en/register" > Register < / a * > < / li * > */ // WebElement liSignIn = driver.findElement(By.className("sign-up-switch amplitude")); By btnRegister = By.linkText("Register"); WebDriverWait wait = new WebDriverWait(driver, 10); wait.until(ExpectedConditions.presenceOfElementLocated(btnRegister)); WebElement anchSignIn = driver.findElement(By.linkText("Register")); anchSignIn.click(); //driver.manage().timeouts().wait(30); Logs logs = driver.manage().logs(); LogEntries logEntries = logs.get(LogType.BROWSER); for (LogEntry logEntry : logEntries) { System.out.println("browser entry: " + logEntry.getMessage()); } //driver.quit(); } catch (Exception ex) { ex.printStackTrace(); } }
From source file:gov.nasa.jpl.memex.nutch.protocol.selenium.handlers.login.LoginHandler34.java
License:Apache License
public void processDriver(WebDriver driver) { try {/*from www.java2 s.c om*/ String accumulatedData = ""; driver.findElement(By.tagName("body")).getAttribute("innerHTML"); Configuration conf = NutchConfiguration.create(); new WebDriverWait(driver, 5); WebElement username = driver.findElement(By.id("username")); username.sendKeys("412651408@qq.com"); WebElement password = driver.findElement(By.id("password")); password.sendKeys("z123456"); WebElement autologin = driver.findElement(By.id("autologin")); if (!autologin.isSelected()) { autologin.click(); } WebElement login = driver.findElement(By.name("longin")); login.click(); (new WebDriverWait(driver, 10)) .until(ExpectedConditions.presenceOfElementLocated(By.className("forabg"))); // Cookie cookie1 = new Cookie("phpbb3_63hz5_sid", "aa31814a45de62c5aa231456f190bf7a"); // driver.manage().addCookie(cookie1); // Cookie cookie2 = new Cookie("phpbb3_63hz5_u", "12328"); // driver.manage().addCookie(cookie2); // Cookie cookie3 = new Cookie("phpbb3_63hz5_k", ""); // driver.manage().addCookie(cookie3); // Cookie cookie4 = new Cookie("style_cookie", "null"); // driver.manage().addCookie(cookie4); // JavascriptExecutor jsx = (JavascriptExecutor) driver; // jsx.executeScript("document.body.innerHTML=document.body.innerHTML " + accumulatedData + ";"); } catch (Exception e) { LOG.info(StringUtils.stringifyException(e)); } }
From source file:influent.selenium.tests.AccountsViewTests.java
License:MIT License
@Test public void searchLoanTest() { SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_ACCOUNTS); List<WebElement> elements = driver.findElements(By.id("influent-view-toolbar-search-input")); WebElement element = SeleniumUtils.getDisplayedElement(elements); if (element == null) { throw new AssertionError("Couldn't find: influent-view-toolbar-search-input element"); }/*from w ww. jav a2 s. c o m*/ element.sendKeys("joe"); elements = driver.findElements(By.className("infGoSearch")); element = SeleniumUtils.getDisplayedElement(elements); if (element == null) { throw new AssertionError("Couldn't find: infGoSearch element"); } element.click(); try { Thread.sleep(1000); } catch (Exception e) { } element = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infSearchResultCounts"))); assertEquals("Showing 12 of 412 results", element.getText()); elements = driver.findElements((By.cssSelector(".simpleSearchResultText"))); element = SeleniumUtils.getDisplayedElement(elements); assertEquals( "Name:JoeDescription:Joe, 40 years old, is still single. He has been managing a livestock business, particularly hog-raising, for almost 10 years. His net income every three months is 6,000 Philippine pesos (PHP) for every hog that he sell. He's asking for a loan of 12,000 PHP to purchase livestock feeds for his hogs. He hopes that Kiva lenders ...", element.getText()); elements = driver.findElements((By.cssSelector(".infSearchResultStateToggle"))); element = SeleniumUtils.getDisplayedElement(elements); element.click(); assertEquals("[less]", element.getText()); elements = driver.findElements((By.cssSelector(".simpleEntityViewTextValue"))); element = SeleniumUtils.getDisplayedElement(elements); assertEquals("PHP", element.getText()); elements = driver.findElements((By.className("transaction-graph"))); element = SeleniumUtils.getDisplayedElement(elements); assertEquals(220, element.getSize().getHeight()); elements = driver.findElements((By.cssSelector(".selectSingleResult input[type='checkbox']"))); element = SeleniumUtils.getDisplayedElement(elements); element.click(); elements = driver.findElements((By.className("searchResultSelected"))); element = SeleniumUtils.getDisplayedElement(elements); if (element == null) { throw new AssertionError("Selected result was not highlighted"); } }
From source file:influent.selenium.tests.AccountsViewTests.java
License:MIT License
@Test public void searchPartnerTest() { SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_ACCOUNTS); List<WebElement> elements = driver.findElements(By.id("influent-view-toolbar-search-input")); WebElement element = SeleniumUtils.getDisplayedElement(elements); if (element == null) { throw new AssertionError("Couldn't find: influent-view-toolbar-search-input element"); }//from w w w. j a v a2s .c o m element.sendKeys("visionfund"); elements = driver.findElements(By.className("infGoSearch")); element = SeleniumUtils.getDisplayedElement(elements); if (element == null) { throw new AssertionError("Couldn't find: infGoSearch element"); } element.click(); try { Thread.sleep(1000); } catch (Exception e) { } element = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infSearchResultCounts"))); assertEquals("Showing 6 of 6 results", element.getText()); elements = driver.findElements((By.cssSelector(".simpleSearchResultText"))); element = SeleniumUtils.getDisplayedElement(elements); assertEquals("Name:VisionFund Albanianame:VisionFund AlbaniaStatus:activeDue Diligence Type:Full", element.getText()); elements = driver.findElements((By.cssSelector(".infSearchResultStateToggle"))); element = SeleniumUtils.getDisplayedElement(elements); element.click(); assertEquals("[less]", element.getText()); elements = driver.findElements((By.cssSelector(".simpleEntityViewTextValue"))); element = SeleniumUtils.getDisplayedElement(elements); assertEquals("AL", element.getText()); elements = driver.findElements((By.className("transaction-graph"))); element = SeleniumUtils.getDisplayedElement(elements); assertEquals(220, element.getSize().getHeight()); }
From source file:influent.selenium.tests.AccountsViewTests.java
License:MIT License
@Test public void searchLenderTest() { SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_ACCOUNTS); List<WebElement> elements = driver.findElements(By.id("influent-view-toolbar-search-input")); WebElement element = SeleniumUtils.getDisplayedElement(elements); if (element == null) { throw new AssertionError("Couldn't find: influent-view-toolbar-search-input element"); }//from w w w. j av a 2 s . co m element.sendKeys("juan ivy"); elements = driver.findElements(By.className("infGoSearch")); element = SeleniumUtils.getDisplayedElement(elements); if (element == null) { throw new AssertionError("Couldn't find: infGoSearch element"); } element.click(); try { Thread.sleep(1000); } catch (Exception e) { } element = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infSearchResultCounts"))); assertEquals("Showing 12 of 3284 results", element.getText()); elements = driver.findElements((By.cssSelector(".simpleSearchResultText"))); element = SeleniumUtils.getDisplayedElement(elements); assertEquals( "Name:Juan IvyLoan Reason:it gives me a sense of accomplishment and allow others success.Occupation:entrepreneur", element.getText()); elements = driver.findElements((By.cssSelector(".infSearchResultStateToggle"))); element = SeleniumUtils.getDisplayedElement(elements); element.click(); assertEquals("[less]", element.getText()); elements = driver.findElements((By.cssSelector(".simpleEntityViewTextValue"))); element = SeleniumUtils.getDisplayedElement(elements); assertEquals("Juan Ivy", element.getText()); elements = driver.findElements((By.className("transaction-graph"))); element = SeleniumUtils.getDisplayedElement(elements); assertEquals(220, element.getSize().getHeight()); }
From source file:influent.selenium.tests.ColdStartAccountsByIdTest.java
License:MIT License
@Test public void coldStartTestBasicTerm() { WebElement element = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.className(this.classToFind))); if (element == null) { throw new AssertionError("Could not find any " + this.classToFind + " elements. The server either did not return any search results for the url or the search failed."); }/*from w w w . java 2 s . c om*/ }
From source file:influent.selenium.tests.EntityDetailsTest.java
License:MIT License
private void getFlowViewResults(String query) { SeleniumUtils.navigateToTab(driver, SeleniumUtils.TAB_ACCOUNTS); List<WebElement> elements = driver.findElements(By.id("influent-view-toolbar-search-input")); WebElement element = SeleniumUtils.getDisplayedElement(elements); if (element == null) { throw new AssertionError("Couldn't find: influent-view-toolbar-search-input element"); }/*w ww . ja va 2s.c om*/ element.sendKeys(query); elements = driver.findElements(By.className("infGoSearch")); element = SeleniumUtils.getDisplayedElement(elements); if (element == null) { throw new AssertionError("Couldn't find: infGoSearch element"); } element.click(); try { Thread.sleep(1000); } catch (Exception e) { } element = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infSearchResultCounts"))); element = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.cssSelector(".infOperationsBar"))); List<WebElement> switchViewButtons = element.findElements(By.cssSelector("[switchesto]")); WebElement switchToFlowButton = null; for (WebElement e : switchViewButtons) { String switchTo = e.getAttribute("switchesto"); if (switchTo.equals(SeleniumUtils.FLOW_NAME)) { switchToFlowButton = e; } } if (switchToFlowButton == null) { throw new AssertionError("Couldn't find: Button to switch to flow view in infOperationsBar"); } List<WebElement> dataIdElements = driver.findElements(By.cssSelector(".selectSingleResult input")); int elementsToSelect = 1; int elementsSelected = 0; for (WebElement e : dataIdElements) { e.click(); elementsSelected++; if (elementsToSelect == elementsSelected) { break; } } switchToFlowButton.click(); try { Thread.sleep(2000); } catch (Exception e) { } }
From source file:influent.selenium.tests.EntityDetailsTest.java
License:MIT License
@Test public void accountsViewButtonTest() { getFlowViewResults("joe"); //Test a card that has no transactions List<WebElement> elements = driver.findElements(By.className("baseballcardContainer")); WebElement card1 = null;//from w ww .j av a2 s . com for (WebElement webElement : elements) { if (webElement.isDisplayed()) { if (card1 == null) { card1 = webElement; break; } } } if (card1 == null) { throw new AssertionError("Couldn't find: baseballcardContainer element"); } card1.click(); //Wait a few seconds for page to load. This is needed despite waiting for presence of element try { Thread.sleep(2000); } catch (Exception e) { } WebElement element = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.id("transactions-table-pagination-label"))); element = driver.findElement(By.id("accountsViewButton")); element.click(); element = (new WebDriverWait(driver, 120)) .until(ExpectedConditions.presenceOfElementLocated(By.className("infSearchResultCounts"))); assertEquals("Showing 1 of 1 results", element.getText()); element = driver.findElement((By.className("simpleSearchResultText"))); assertEquals( "Name:JoeDescription:Joe, 40 years old, is still single. He has been managing a livestock business, particularly hog-raising, for almost 10 years. His net income every three months is 6,000 Philippine pesos (PHP) for every hog that he sell. He's asking for a loan of 12,000 PHP to purchase livestock feeds for his hogs. He hopes that Kiva lenders ...", element.getText()); }