Skip to content

Instantly share code, notes, and snippets.

@bensullivan
Created January 25, 2013 04:10
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bensullivan/4631660 to your computer and use it in GitHub Desktop.
Save bensullivan/4631660 to your computer and use it in GitHub Desktop.
Groovy Selenium Demo
import org.openqa.selenium.By
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.support.ui.WebDriverWait
import static org.openqa.selenium.support.ui.ExpectedConditions.*
def browser = new FirefoxDriver()
browser.manage().window().maximize()
browser.get('http://translate.google.com/')
def wait = new WebDriverWait(browser, 10)
def languageButton = browser.findElementById('gt-sl-gms')
languageButton.click()
def norwegianLanguageLinkLocator = By.xpath("//div[text()='Norwegian']")
wait.until(elementToBeClickable(norwegianLanguageLinkLocator))
browser.findElement(norwegianLanguageLinkLocator).click()
println languageButton.text
browser.findElementById('source').sendKeys('ost')
def resultTextBoxLocator = By.cssSelector('#result_box span')
//wait.until(presenceOfElementLocated(resultTextBoxLocator))
wait.until(not(textToBePresentInElement(resultTextBoxLocator, '')))
def result_box = browser.findElement(resultTextBoxLocator)
println "Result text: \"${result_box.text}\""
browser.quit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment