radiofreekruzr

Untitled

Mar 1st, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. package com.reticulum.mds;
  2.  
  3. /**
  4.  * Created by jtd on 2/25/16.
  5.  */
  6.  
  7. /* import org.junit.Test; */
  8. import org.openqa.selenium.By;
  9. import org.openqa.selenium.WebDriver;
  10. import org.openqa.selenium.WebElement;
  11. import org.openqa.selenium.firefox.FirefoxDriver;
  12. import org.openqa.selenium.support.ui.ExpectedCondition;
  13. import org.openqa.selenium.support.ui.Wait;
  14. import org.openqa.selenium.support.ui.WebDriverWait;
  15.  
  16. import java.util.List;
  17.  
  18. public class Cheese {
  19.  
  20.     /* @Test */
  21.  
  22.     public static void main(String [ ] args) {
  23.         WebDriver driver = new FirefoxDriver();
  24.         Wait<WebDriver> wait = new WebDriverWait(driver, 30);
  25.         driver.get("http://www.google.co.uk/");
  26.         WebElement searchBox = driver.findElement(By.name("q"));
  27.         searchBox.sendKeys("cheese\n");
  28.         WebElement link = wait.until(textIsPresent("Cheese.com"));
  29.         link.click();
  30.     }
  31.  
  32.     private ExpectedCondition<WebElement> textIsPresent(final String text) {
  33.         return new ExpectedCondition<WebElement>() {
  34.             public WebElement apply(WebDriver driver) {
  35.                 List<WebElement> allLinks = driver.findElements(By.tagName("a"));
  36.                 for (WebElement link : allLinks) {
  37.                     if (link.getText().contains(text)) {
  38.                         return link;
  39.                     }
  40.                 }
  41.                 return null;
  42.             }
  43.         };
  44.     };
  45. }
Advertisement
Add Comment
Please, Sign In to add comment