List of usage examples for org.openqa.selenium.support.ui ExpectedConditions presenceOfElementLocated
public static ExpectedCondition<WebElement> presenceOfElementLocated(final By locator)
From source file:com.comcast.dawg.house.EditDeviceUIIT.java
License:Apache License
private void waitForNewPageToLoad(RemoteWebDriver driver, WebElement oldPageElement) { WebDriverWait wait = new WebDriverWait(driver, 20); wait.until(ExpectedConditions.stalenessOf(oldPageElement)); wait.until(ExpectedConditions.presenceOfElementLocated(By.className(IndexPage.FILTERED_TABLE))); }
From source file:com.comcast.dawg.house.pages.IndexPage.java
License:Apache License
/** * Types the tag name and clicks the bulk tag button. * * @param tagName the tag names/*from w ww . j a va 2s.c om*/ */ public void enterTagNameAndClickSubmit(String tagName) { // Enter the tag name. typeOnBulkTagTextElement(tagName); /** * If already tag is present in the tag cloud the element modification need to be evaluated for correct wait * time. **/ String tagCloudElementText = getTagCloudElementText(); boolean isTagPresent = false; List<WebElement> listOfContainedTag = new ArrayList<WebElement>(); for (String tag : tagName.split(" ")) { if (tagCloudElementText.contains(tag)) { isTagPresent = true; listOfContainedTag .add(driver.findElementByXPath(TAG_ID_DIV_XPATH.replace(REPLACEABLE_ELEMENT, tag))); } } // Clicking on bulk tag add button. clickOnBulkTagAddButton(); WebDriverWait wait = new WebDriverWait(driver, 20); // If tag is present waiting for it to get refreshed. if (isTagPresent) { for (WebElement element : listOfContainedTag) { wait.until(ExpectedConditions.stalenessOf(element)); } } // Since multi tag addition is supported. for (String tag : tagName.split(" ")) { wait.until(ExpectedConditions .presenceOfElementLocated(By.xpath(TAG_ID_DIV_XPATH.replace(REPLACEABLE_ELEMENT, tag)))); } }
From source file:com.comcast.dawg.selenium.SeleniumWaiter.java
License:Apache License
/** * It will wait till the presence of element on the DOM. If wait time go beyond to expected * timeout it will throw time out exception. * * @param locatorName element locator. * @param timeoutInSec timeout in seconds. * * @return The functions' return value if the function returned something different from null * or false before the timeout expired. *//*from ww w . ja va 2 s .c o m*/ public WebElement waitForPresence(By locatorName, int timeoutInSec) { WebDriverWait wait = new WebDriverWait(driver, timeoutInSec); return wait.until(ExpectedConditions.presenceOfElementLocated(locatorName)); }
From source file:com.daarons.transfer.DownloadTask.java
License:Apache License
private void acceptToS() { try {//from w ww . ja v a2 s . c o m WebElement acceptButton = smallWait .until(ExpectedConditions.presenceOfElementLocated(By.className("transfer__button"))); acceptButton.click(); } catch (Exception ex) { log.error("Couldn't accept ToS", ex); } }
From source file:com.daarons.transfer.DownloadTask.java
License:Apache License
private String getFileName() { String fileName = null;/*from www . ja v a2 s .co m*/ try { WebElement fileNameElement = longWait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector( "body > div > div > div.transfer > div > div.scrollable.transfer__contents > div.scrollable__content > ul > li > span.filelist__name"))); fileName = fileNameElement.getText(); } catch (Exception e) { log.error(e); } return fileName; }
From source file:com.daarons.transfer.DownloadTask.java
License:Apache License
private void clickDownloadButton() { WebElement downloadButton = smallWait .until(ExpectedConditions.presenceOfElementLocated(By.className("transfer__button"))); downloadButton.click();/*www .j a va 2 s. c o m*/ }
From source file:com.daarons.transfer.UploadTask.java
License:Apache License
@Override protected Object call() throws Exception { initUploadTask();//from w ww. ja va 2 s .c o m acceptToS(); //put before login? String emailAddress = getTransferSettingsController().getEmailAddress(); String password = getTransferSettingsController().getPassword(); boolean loggedIn = false; if (!emailAddress.isEmpty() && !password.isEmpty()) { loggedIn = logIn(emailAddress, password); } Iterator<UploadTransferObject> i = uploadList.iterator(); while (i.hasNext()) { UploadTransferObject uploadTransferObject = i.next(); clickButtonToChooseEmailOrLink(); Message message = uploadTransferObject.getMessage(); boolean sendingEmail = false; boolean gettingLink = false; if (message != null) { clickEmailButton(); inputMessage(message); sendingEmail = true; } else { clickLinkButton(); gettingLink = true; } String uploadPassword = uploadTransferObject.getPassword(); if (uploadPassword != null && loggedIn) { enterUploadPassword(uploadPassword); } clickButtonToChooseEmailOrLink(); inputFilePath(uploadTransferObject.getUrl()); clickTransferButtonWithText("Transfer"); String downloadLink = null; int timeWaited = 0; boolean isUploadTimeAvailable = isUploadTimeAvailable(longWait); boolean isLinkAvailable = false; boolean isEmailSent = false; if (!isUploadTimeAvailable) { //check if the upload if finished. Maybe it was a small file and uploaded quickly. if (sendingEmail) { isEmailSent = isTransferButtonWithTextAvailable("Send another?", longWait); } else if (gettingLink) { isLinkAvailable = isLinkAvailable(smallWait); } //if upload isn't finished if (!isEmailSent && !isLinkAvailable) { //look for upload time again isUploadTimeAvailable = isUploadTimeAvailable(longWait); if (!isUploadTimeAvailable) { log.error("Couldn't upload this file. Continuing to next file."); TransferRecord transferRecord = createTransferRecord(uploadTransferObject, "Failed"); dao.addTransferRecord(transferRecord); continue; } } } if (isUploadTimeAvailable) { int timeUntilUploadFinished = getUploadTime(smallWait); //create new webdriverwait based on upload time + some extra time //just in case slow connection WebDriverWait uploadWait = new WebDriverWait(driver, (timeUntilUploadFinished * 60) + (30 * 60)); if (sendingEmail) { isEmailSent = isTransferButtonWithTextAvailable("Send another?", uploadWait); } else if (gettingLink) { isLinkAvailable = isLinkAvailable(uploadWait); } if (!isEmailSent && !isLinkAvailable) { log.error("The upload time is done, but the web element cannot be found"); if (isUploadTimeAvailable(smallWait)) { timeWaited += (timeUntilUploadFinished * 60) + (30 * 60); timeUntilUploadFinished = getUploadTime(smallWait); uploadWait = new WebDriverWait(driver, (timeUntilUploadFinished * 60) + (30 * 60)); //calculate time waited if there's a future failure timeWaited += (timeUntilUploadFinished * 60) + (30 * 60); timeWaited /= 60;//time waited in minutes for failure if (sendingEmail) { isEmailSent = isTransferButtonWithTextAvailable("Send another?", uploadWait); } else if (gettingLink) { isLinkAvailable = isLinkAvailable(uploadWait); } if (!isEmailSent && !isLinkAvailable) { log.error("Couldn't upload this file. Continuing to next file."); TransferRecord transferRecord = createTransferRecord(uploadTransferObject, "Failed"); dao.addTransferRecord(transferRecord); continue; } } else if (sendingEmail && !isTransferButtonWithTextAvailable("Send another?", smallWait)) { log.error("Couldn't upload this file. Continuing to next file."); TransferRecord transferRecord = createTransferRecord(uploadTransferObject, "Failed"); dao.addTransferRecord(transferRecord); continue; } else if (gettingLink && !isLinkAvailable(smallWait)) { log.error("Couldn't upload this file. Continuing to next file."); TransferRecord transferRecord = createTransferRecord(uploadTransferObject, "Failed"); dao.addTransferRecord(transferRecord); continue; } } } WebElement linkElement = null; if (gettingLink) { linkElement = smallWait .until(ExpectedConditions.presenceOfElementLocated(By.className("transfer__textfield"))); downloadLink = linkElement.getAttribute("value"); } if (sendingEmail) { downloadLink = message.getTo().replaceAll(",", " "); } TransferRecord transferRecord = createTransferRecord(uploadTransferObject, downloadLink); dao.addTransferRecord(transferRecord); try { if (gettingLink) { linkElement.click(); clickTransferButtonWithText("Ok"); } else if (isEmailSent) { clickTransferButtonWithText("Send another?"); } clickTransferButtonWithText("Continue"); Thread.sleep(5000); } catch (Exception ex) { log.error("Couldn't click button. Uploading next file.", ex); } } if (loggedIn) { logOut(); try { Thread.sleep(3000); } catch (InterruptedException ex) { log.error(ex); } } clearTableView("upload"); driver.quit(); return null; }
From source file:com.daarons.transfer.UploadTask.java
License:Apache License
private void clickTransferButtonWithText(String text) throws Exception { if (isTransferButtonWithTextAvailable(text, longWait)) { WebElement transferButton = smallWait .until(ExpectedConditions.presenceOfElementLocated(By.className("transfer__button"))); transferButton.click();//from w w w .ja v a 2 s . c o m } else { throw new Exception("Button with text " + text + " does not exist"); } }
From source file:com.daarons.transfer.UploadTask.java
License:Apache License
private boolean logIn(String emailAddress, String password) { try {/*from w ww . ja v a 2 s .co m*/ WebElement emailInput = longWait.until(ExpectedConditions.presenceOfElementLocated( By.cssSelector("#signin__form > div > div > form > div:nth-child(1) > input"))); emailInput.sendKeys(emailAddress); WebElement passwordInput = longWait.until(ExpectedConditions.presenceOfElementLocated( By.cssSelector("#signin__form > div > div > form > div:nth-child(2) > input"))); passwordInput.sendKeys(password); WebElement logInButton = longWait.until(ExpectedConditions .presenceOfElementLocated(By.cssSelector("#signin__form > div > div > form > button"))); logInButton.click(); Thread.sleep(5000); return true; } catch (Exception ex) { log.error("Problem", ex); return false; } }
From source file:com.daarons.transfer.UploadTask.java
License:Apache License
private void clickButtonToChooseEmailOrLink() { WebElement emailOrLinkButton = longWait.until(ExpectedConditions.presenceOfElementLocated(By.cssSelector( "body > div > div > div.transfer.transfer--half-panel > div > div.transfer__footer > svg"))); emailOrLinkButton.click();//from w w w . j ava 2 s . com }