Advertisement
Guest User

Untitled

a guest
Apr 8th, 2015
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.36 KB | None | 0 0
  1. package dk.mehmedbasic
  2.  
  3. import java.net.URL
  4. import java.util.concurrent.TimeUnit
  5.  
  6. import org.openqa.selenium.remote.{BrowserType, DesiredCapabilities, RemoteWebDriver}
  7. import org.openqa.selenium.support.ui.Select
  8. import org.openqa.selenium.{By, Platform, WebDriver}
  9.  
  10. object Test {
  11.    var driver: WebDriver = null
  12.  
  13.    def main(args: Array[String]) {
  14.       setupWebDriver()
  15.       driver.navigate().to("http://www.myprotein.com/sports-nutrition/impact-whey-protein/10530943.html")
  16.       val list = driver.findElements(By.className("locale-overlay"))
  17.       val overlay = if (list.isEmpty) {
  18.          null
  19.       } else {
  20.          list.get(0)
  21.       }
  22.  
  23.       if (overlay != null && overlay.isDisplayed) {
  24.          overlay.findElement(By.id("button2")).click()
  25.       }
  26.       val select = new Select(driver.findElement(By.id("opts-7")))
  27.       select.selectByIndex(1)
  28.  
  29.  
  30.       println(driver.findElement(By.className("product-price")).getText())
  31.  
  32.    }
  33.  
  34.    def setupWebDriver() {
  35.       val caps: DesiredCapabilities = new DesiredCapabilities()
  36.       caps.setJavascriptEnabled(true)
  37.       caps.setBrowserName(BrowserType.GOOGLECHROME)
  38.       caps.setPlatform(Platform.LINUX)
  39.       //driver = new PhantomJSDriver(caps)
  40.       driver = new RemoteWebDriver(new URL("http://localhost:9515"), caps)
  41.       driver.manage.timeouts.implicitlyWait(10, TimeUnit.SECONDS)
  42.    }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement