Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- package com.reticulum.mds;
- /**
- * Created by jtd on 2/25/16.
- */
- /* import org.junit.Test; */
- import org.openqa.selenium.By;
- import org.openqa.selenium.WebDriver;
- import org.openqa.selenium.WebElement;
- import org.openqa.selenium.firefox.FirefoxDriver;
- import org.openqa.selenium.support.ui.ExpectedCondition;
- import org.openqa.selenium.support.ui.Wait;
- import org.openqa.selenium.support.ui.WebDriverWait;
- import java.util.List;
- public class Cheese {
- /* @Test */
- public static void main(String [ ] args) {
- WebDriver driver = new FirefoxDriver();
- Wait<WebDriver> wait = new WebDriverWait(driver, 30);
- driver.get("http://www.google.co.uk/");
- WebElement searchBox = driver.findElement(By.name("q"));
- searchBox.sendKeys("cheese\n");
- WebElement link = wait.until(textIsPresent("Cheese.com"));
- link.click();
- }
- private ExpectedCondition<WebElement> textIsPresent(final String text) {
- return new ExpectedCondition<WebElement>() {
- public WebElement apply(WebDriver driver) {
- List<WebElement> allLinks = driver.findElements(By.tagName("a"));
- for (WebElement link : allLinks) {
- if (link.getText().contains(text)) {
- return link;
- }
- }
- return null;
- }
- };
- };
- }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

