本文整理汇总了Scala中org.openqa.selenium.htmlunit.HtmlUnitDriver类的典型用法代码示例。如果您正苦于以下问题:Scala HtmlUnitDriver类的具体用法?Scala HtmlUnitDriver怎么用?Scala HtmlUnitDriver使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了HtmlUnitDriver类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。
示例1: Hello
//设置package包名称以及导入依赖的类
package com.example
import org.openqa.selenium.{By, WebElement}
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import scala.collection.JavaConversions._
object Hello {
def main(args: Array[String]): Unit = {
val url = "http://www.shigemk2.com"
val driver = new HtmlUnitDriver()
driver.get(url)
println(s"title: ${driver.getTitle()}")
driver.findElementByXPath("//div[@id='container']")
.findElements(By.xpath("//a[@class='entry-title-link bookmark']"))
.foreach{ we: WebElement =>
println(s"title: ${we.getText()}")
println(s"link: ${we.getAttribute("href")}")
}
println("Hello, world!")
}
}
示例2: WebTestDemoFunSuiteStyle
//设置package包名称以及导入依赖的类
package org.whunmr.scalatestdemo
import org.openqa.selenium._
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.scalatest.selenium.WebBrowser
import org.scalatest.{FunSuite, Matchers}
class WebTestDemoFunSuiteStyle extends FunSuite with Matchers with WebBrowser {
implicit val webDriver: WebDriver = new HtmlUnitDriver
val host = "http://www.baidu.com"
test("Google browser works!") {
go to (host)
click on "kw"
textField("kw").value = "Cheese!"
submit()
assert (pageTitle contains ("Cheese!") )
}
}
示例3: FormElementSpec
//设置package包名称以及导入依赖的类
package com.yukimt.scrape.element
import org.specs2.mutable.Specification
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import org.json4s.JObject
import org.json4s.jackson.JsonMethods
import ParserMethod._
import ElementMethod._
class FormElementSpec extends Specification{
sequential
implicit val driver = new HtmlUnitDriver(true)
driver.get("http://localhost:3000/view")
val parser = new Parser(driver)
var element = (parser >> css("form")) >> asForm
"FormElement" should {
"set query string" in {
element.setQueryString(Map("a"->"b", "c"->"d"))
element >> url === "/form?a=b&c=d"
}
"submit" in {
driver.getTitle === "Express Sample Title"
element.submit
driver.getTitle === ""
}
"add form data" in {
driver.navigate.back
element = (parser >> css("form")) >> asForm
driver.getTitle === "Express Sample Title"
element.addFormData("abc", "def")
element.submit
driver.getTitle === ""
val result = JsonMethods.parse(driver.getPageSource.replaceAll("<.+>", "")).asInstanceOf[JObject].values.asInstanceOf[Map[String, String]]
result === Map("text"->"default","textarea"->"","fruit"->"a","select"->"select1","abc"->"def")
}
"set uri" in {
driver.navigate.back
element = (parser >> css("form")) >> asForm
element.setUri("/abc")
element >> url === "/abc"
}
}
}
示例4: ATagElementSpec
//设置package包名称以及导入依赖的类
package com.yukimt.scrape.element
import org.specs2.mutable.Specification
import org.openqa.selenium.htmlunit.HtmlUnitDriver
import ParserMethod._
import ElementMethod._
class ATagElementSpec extends Specification{
sequential
implicit val driver = new HtmlUnitDriver(true)
driver.get("http://localhost:3000/view")
val parser = new Parser(driver)
val element = (parser >> css("a")) >> asATag
"ATagElement" should {
"set query string" in {
element.setQueryString(Map("a"->"b", "c"->"d"))
element >> url === "http://localhost:3000/?a=b&c=d"
}
"set uri" in {
element.setUri("/abc")
element >> url === "http://localhost:3000/abc"
}
"open in new window" in {
element.setUri("/")
driver.getTitle === "Express Sample Title"
val id = driver.getWindowHandle
driver.switchTo.window(element.openInNewWindow.id)
driver.getTitle === ""
}
}
}