Last active
August 30, 2015 13:08
-
-
Save antsmartian/68d6555de8bece15d2c4 to your computer and use it in GitHub Desktop.
Flipkart selenium
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.TimeUnit; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.NoSuchElementException; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.firefox.FirefoxDriver; | |
import org.openqa.selenium.support.ui.FluentWait; | |
import com.google.common.base.Function; | |
public class FlipkartCodingSession1 { | |
private static final String ADDRESS = "http://www.flipkart.com"; | |
private static final String SEARCH_BOX = "fk-top-search-box"; | |
private static final String SEARCH_RESULT = "//li[contains(text(),'webdriver')]"; | |
public static void main(String[] args) { | |
WebDriver driver = new FirefoxDriver(); | |
driver.get(ADDRESS); | |
driver.findElement(By.id(SEARCH_BOX)).sendKeys("Selenium"); | |
WebElement seleniumSearchResult = fluentWait(By.xpath(SEARCH_RESULT), driver); | |
seleniumSearchResult.click(); | |
} | |
public static WebElement fluentWait(final By locator, WebDriver driver) | |
{ | |
FluentWait<WebDriver> wait = new FluentWait<WebDriver>(driver) | |
.withTimeout(30,TimeUnit.SECONDS) | |
.pollingEvery(5, TimeUnit.SECONDS) | |
.ignoring(NoSuchElementException.class); | |
//f(x) = x , is any integer and gives back y , which is an any integer | |
WebElement element = wait.until(new Function<WebDriver,WebElement>() { | |
@Override | |
public WebElement apply(WebDriver arg0) { | |
// TODO Auto-generated method stub | |
return arg0.findElement(locator); | |
} | |
}); | |
return element; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment