Created
November 29, 2011 21:46
-
-
Save salomvary/1406691 to your computer and use it in GitHub Desktop.
check iPhone availability with 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 org.openqa.selenium._ | |
import org.openqa.selenium.support.ui._ | |
import org.openqa.selenium.chrome.ChromeDriver | |
import org.openqa.selenium.firefox.FirefoxDriver | |
import org.openqa.selenium.htmlunit.HtmlUnitDriver | |
import org.openqa.selenium.remote.DesiredCapabilities | |
import scala.collection.JavaConversions._ | |
import scala.actors.Actor._ | |
object Available { | |
def main(args: Array[String]): Unit = { | |
val stores = Seq( | |
"Apple Store, SoHo", | |
"Apple Store, West 14th Street", | |
"Apple Store, Fifth Avenue", | |
"Apple Store, Upper West Side") | |
stores.foreach { store => | |
actor { | |
val driver = new FirefoxDriver() | |
driver.get("http://www.apple.com/retail/iphone/") | |
driver.findElement(By.cssSelector(".reserve a.button")).click() | |
new Select(driver.findElement(By.id("state"))).selectByValue("New York") | |
new Select(driver.findElement(By.id("store"))).selectByVisibleText(store) | |
driver.findElement(By.id("fwdButtonC")).click() | |
val title = driver.findElements(By.tagName("h6")).get(3).getText() | |
if(title != "iPhone 4S Unlocked (GSM)3") { | |
throw new Exception("unexpected title:"+title) | |
} | |
val table = driver.findElements(By.cssSelector(".grid3col")).get(3) | |
var out = store + "\n" | |
table.findElements(By.cssSelector(".column")).foreach { col => | |
out += col.getText().replaceAll("\n", " ") + "\n" | |
} | |
println(out) | |
driver.quit() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment