Skip to content

Instantly share code, notes, and snippets.

@mwacc
Created June 13, 2014 17:46
Show Gist options
  • Save mwacc/055067d82ba17362fdee to your computer and use it in GitHub Desktop.
Save mwacc/055067d82ba17362fdee to your computer and use it in GitHub Desktop.
example of groovy script + selenium webdriver (maven artefact is loaded by anotation)
@Grab(group="org.seleniumhq.selenium", module="selenium-java", version="2.42.2")
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.*;
System.setProperty("webdriver.chrome.driver", "/Users/kostya/Downloads/chromedriver");
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--verbose", "--ignore-certificate-errors");
WebDriver driver = new ChromeDriver();
driver.get("http://auto.ria.com/?target=search&event=big&city=&state=5&category_id=1&marka=75&model=663&currency=1&page=0");
List<WebElement> advs = driver.findElements(By.cssSelector("div.content-bar"));
for(WebElement e : advs) {
try {
WebElement header = e.findElement(By.cssSelector("h3 > a"))
println header.getText();
} catch(all) { }
}
driver.close();
driver.quit();
@wildone
Copy link

wildone commented Jun 5, 2017

What language is groovy?

@sanjeets
Copy link

This code is in java not groovy
whats going on?

@mwacc
Copy link
Author

mwacc commented Sep 5, 2018

@havryliuk @sanjeets Java code is a valid subset of Groovy, so everything is fine here and as for 2015 was a good way to execute some Java code in a-al script way

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment