本文整理汇总了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!")
}
}
开发者ID:shigemk2,项目名称:my-webdriver-htmlunit-sample,代码行数:22,代码来源:Hello.scala
示例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!") )
}
}
开发者ID:whunmr,项目名称:ScalaTestDemo,代码行数:22,代码来源:WebTestDemoFunSuiteStyle.scala
示例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"
}
}
}
开发者ID:yuki-mt,项目名称:scraper4s,代码行数:48,代码来源:FormElementSpec.scala
示例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 === ""
}
}
}
开发者ID:yuki-mt,项目名称:scraper4s,代码行数:35,代码来源:ATagElementSpec.scala
注:本文中的org.openqa.selenium.htmlunit.HtmlUnitDriver类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论