当前位置: 首页>>代码示例>>Scala>>正文


Scala WebElement类代码示例

本文整理汇总了Scala中org.openqa.selenium.WebElement的典型用法代码示例。如果您正苦于以下问题:Scala WebElement类的具体用法?Scala WebElement怎么用?Scala WebElement使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了WebElement类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Scala代码示例。

示例1: MessagesPage

//设置package包名称以及导入依赖的类
package uitest.pages

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.FindBy
import uitest.commands.SeleniumCommands

class MessagesPage(driver: WebDriver) {
  private val sc: SeleniumCommands = new SeleniumCommands(driver)

  @FindBy(css = "#logoutLink")
  val logoutLink: WebElement = null

  @FindBy(css = ".alert-info")
  val infoAlert: WebElement = null

  @FindBy(css = ".alert-danger")
  val errorAlert: WebElement = null

  @FindBy(css = "textarea")
  val messageField: WebElement = null

  @FindBy(css = "input[type=submit]")
  val sendButton: WebElement = null

  def logout() {
    logoutLink.click()
    sc.waitForFinishLoading()
  }

  def isUserLogged(user: String): Boolean = {
    sc.waitForElementVisible(By.linkText("Logged in as " + user))
    true
  }

  def isUMessageDisplayed(message: String): Boolean = {
    val escapedMessage = message.replace("\"", "\\\"")
    sc.waitForElementVisible(By.xpath(s"""//span[contains(., "$escapedMessage")]"""))
    true
  }

  def getInfoText: String = {
    sc.waitForElementVisible(By.cssSelector(".alert-info"))
    infoAlert.getText
  }

  def getErrorText: String = {
    sc.waitForElementVisible(By.cssSelector(".alert-danger"))
    errorAlert.getText
  }
} 
开发者ID:GitsAndGlamour,项目名称:acromancer-game,代码行数:53,代码来源:MessagesPage.scala

示例2: SeleniumCommands

//设置package包名称以及导入依赖的类
package uitest.commands

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.ui.ExpectedConditions
import org.openqa.selenium.support.ui.FluentWait
import org.openqa.selenium.support.ui.Wait

import java.util.concurrent.TimeUnit

class SeleniumCommands(driver: WebDriver) {
  final val URL = "http://localhost:8080/#/"

  var fluentwait: Wait[WebDriver] = new FluentWait[WebDriver](driver)
    .withTimeout(20, TimeUnit.SECONDS)
    .pollingEvery(100, TimeUnit.MILLISECONDS)

  def waitForFinishLoading() {
    waitForElementInvisible(By.cssSelector("#loading-indicator"))
  }

  def waitForElementClickable(locator: By) {
    fluentwait.until(ExpectedConditions.elementToBeClickable(locator))
  }

  def waitForElementVisible(element: WebElement) {
    fluentwait.until(ExpectedConditions.visibilityOf(element))
  }

  def waitForElementVisible(locator: By) {
    fluentwait.until(ExpectedConditions.visibilityOfElementLocated(locator))
  }

  def waitForElementInvisible(locator: By) {
    fluentwait.until(ExpectedConditions.invisibilityOfElementLocated(locator))
  }

  def waitForElementPresent(locator: By) {
    fluentwait.until(ExpectedConditions.presenceOfElementLocated(locator))
  }
} 
开发者ID:OOSINT,项目名称:NorthendLink-Site,代码行数:43,代码来源:SeleniumCommands.scala

示例3: DriverContainer

//设置package包名称以及导入依赖的类
package com.github.cuzfrog.webdriver

import org.openqa.selenium.{WebDriver, WebElement}

private[webdriver] sealed trait Container {
  val driver: Driver
}
private[webdriver] case class DriverContainer(driver: Driver, seleniumDriver: WebDriver) extends Container {
  val elements = scala.collection.mutable.ArrayBuffer.empty[Long]
}
private[webdriver] case class ElementContainer(element: Element, seleniumElement: WebElement) extends Container {
  val driver = element.driver
}
private[webdriver] case class WindowContainer(window: Window, seleniumDriver: WebDriver) extends Container {
  val driver = window.driver
} 
开发者ID:cuzfrog,项目名称:WebDriverServ,代码行数:17,代码来源:Container.scala

示例4: step

//设置package包名称以及导入依赖的类
import org.openqa.selenium.{JavascriptExecutor, WebDriver, WebElement}
import org.slf4j.LoggerFactory

import scala.concurrent.duration._

package object tools {

  val logger = LoggerFactory.getLogger("tools")

  def step(caption: String)(lambda: WebDriver => StepResult) =
    Step(caption, lambda)

  def scenario(name: String)(steps: Step*): Scenario =
    Scenario(name, steps)

  def assert(message: String, f: => Boolean) = {
    if (!f) {
      val exception = new AssertionError(message)
      throw exception
    } else {
      StepResult.Ok
    }
  }

  def fail(message: String): Unit = {
    throw new AssertionError(message)
  }

  def sleep(duration: FiniteDuration): Unit = {
    Thread.sleep(duration.toMillis)
  }

  implicit final class WebElementOps(val el: WebElement) extends AnyVal {
    def scrollTo()(implicit webDriver: WebDriver): Unit = webDriver match {
      case executor: JavascriptExecutor =>
        executor.executeScript("arguments[0].scrollIntoView(true);", el)
        ()
      case _ =>
        throw new UnsupportedOperationException("WebDriver is not javascript executor")
    }
  }
} 
开发者ID:fomkin,项目名称:korolev,代码行数:43,代码来源:package.scala

示例5: LoginPage

//设置package包名称以及导入依赖的类
package uitest.pages

import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.FindBy
import uitest.commands.SeleniumCommands

class LoginPage(driver: WebDriver) {
  private val sc: SeleniumCommands = new SeleniumCommands(driver)
  val url = sc.URL + "login"

  @FindBy(name = "login")
  val loginField: WebElement = null

  @FindBy(name = "password")
  val passwordField: WebElement = null

  @FindBy(css = "button[type=submit]")
  val loginButton: WebElement = null

  def login(login: String, password: String) {
    loginField.sendKeys(login)
    passwordField.sendKeys(password)
    loginButton.click()
    sc.waitForFinishLoading()
  }

  def openLoginPage() {
    driver.get(url)
    sc.waitForFinishLoading()
  }
} 
开发者ID:GitsAndGlamour,项目名称:acromancer-game,代码行数:33,代码来源:LoginPage.scala

示例6: RegistrationPage

//设置package包名称以及导入依赖的类
package uitest.pages

import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.support.FindBy
import uitest.commands.SeleniumCommands

class RegistrationPage(driver: WebDriver) {
  private val sc: SeleniumCommands = new SeleniumCommands(driver)
  val url = sc.URL + "register"

  @FindBy(name = "login")
  val loginField: WebElement = null

  @FindBy(name = "email")
  val emailField: WebElement = null

  @FindBy(name = "password")
  val passwordField: WebElement = null

  @FindBy(name = "repeatPassword")
  val repeatPassField: WebElement = null

  @FindBy(css = "button[type=submit]")
  val registerButton: WebElement = null

  @FindBy(id = "regPassDontMatch")
  val registerPassErrorText: WebElement = null

  def register(login: String, email: String, password: String, repeatedPassword: Option[String] = None) {
    openRegistrationPage()
    loginField.sendKeys(login)
    emailField.sendKeys(email)
    passwordField.sendKeys(password)
    repeatPassField.sendKeys(repeatedPassword.getOrElse(password))
    registerButton.click()
    sc.waitForFinishLoading()
  }

  def openRegistrationPage() {
    driver.get(url)
    sc.waitForFinishLoading()
  }

  def getPassErrorText = registerPassErrorText.getText
} 
开发者ID:GitsAndGlamour,项目名称:acromancer-game,代码行数:47,代码来源:RegistrationPage.scala

示例7: PasswordResetPage

//设置package包名称以及导入依赖的类
package uitest.pages

import org.openqa.selenium.{By, WebDriver, WebElement}
import org.openqa.selenium.support.FindBy
import uitest.commands.SeleniumCommands

class PasswordResetPage(driver: WebDriver) {
  private val sc: SeleniumCommands = new SeleniumCommands(driver)
  def url(code: String) = s"${sc.URL}password-reset?code=$code"

  @FindBy(name = "password")
  val passwordField: WebElement = null

  @FindBy(id = "repeatNotMatching")
  val repeatErrorText: WebElement = null

  @FindBy(name = "repeatPassword")
  val repeatPassField: WebElement = null

  @FindBy(css = "button[type=submit]")
  val resetButton: WebElement = null

  def resetPassword(password: String, repeatedPassword: String) {
    passwordField.sendKeys(password)
    repeatPassField.sendKeys(repeatedPassword)
    resetButton.click()
    sc.waitForFinishLoading()
  }

  def openPasswordResetPage(code: String) {
    driver.get(url(code))
    sc.waitForFinishLoading()
  }

  def getErrorText = repeatErrorText.getText
} 
开发者ID:GitsAndGlamour,项目名称:acromancer-game,代码行数:37,代码来源:PasswordResetPage.scala

示例8: MomondoScrapingActor

//设置package包名称以及导入依赖的类
import akka.actor.Actor
import java.time.LocalDate
import org.openqa.selenium.WebElement
import org.openqa.selenium.By._

class MomondoScrapingActor extends Actor {
  import MomondoScrapingActor._
  //org.apache.log4j.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(org.apache.log4j.Level.FATAL);
//java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF)
//java.util.logging.Logger.getLogger("org.apache.commons.httpclient").setLevel(java.util.logging.Level.OFF)
//System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog")
  def receive = {
    case m: MomondoModel => sender ! scrapeFlights(m.searchFlightUrl, m.trip.legs(0).date)
    case s: String => sender ! scrapeFlights(s, LocalDate.now())
  }
  
  def scrapeFlights(url: String, date: LocalDate) = {
    import org.openqa.selenium.chrome.ChromeDriver
    import scala.collection.JavaConversions._
    val chrome = new ChromeDriver()
    val p = "Sökningen är klar".r
    chrome.get(url)
    var m: Option[String] = None
    do {
      Thread.sleep(4000)
      val html = chrome.findElementByTagName("html")
      m = p.findFirstIn(html.getText)
    } while (m.isEmpty)
    val results = chrome.findElementsByCssSelector("div.result-box-inner")
    val flights = results.map(r => Flight(getTravelTime(r), getPrice(r), date))
    chrome.quit
    flights
  }
  
  private def getTravelTime(element: WebElement) = {
    val s = element.findElement(new ByCssSelector("div.travel-time")).getText
    val pattern = """(\d+)tim (\d+)min""".r
    val m = pattern.findAllIn(s)
    val mdata = m.matchData.next
    val hours = mdata.group(1).toInt
    val minutes = mdata.group(2).toInt
    60 * hours + minutes
  }
  
  private def getPrice(element: WebElement) = {
    val s = element.findElement(new ByCssSelector("span.value")).getText
    s.replaceAll("""[\D]""", "").toInt
  }
}

object MomondoScrapingActor {
  case class Flight(totalMinutes: Int, price: Int, flightDate: LocalDate)
} 
开发者ID:hnrklssn,项目名称:momondo-massiveness,代码行数:54,代码来源:htmlactor.scala

示例9: MbankService

//设置package包名称以及导入依赖的类
package services

import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.support.ui.{WebDriverWait, ExpectedCondition}
import org.openqa.selenium.{WebElement, By, WebDriver}
import play.api.Play

class MbankService {

  var currentBalance: Double = 0

  def getCurrentBalance: Double = {
    if (currentBalance == 0) {
      implicit val driver: WebDriver = new FirefoxDriver()

      driver.get(getConfig("loginPage"))
      driver.findElement(By.id("userID")).sendKeys(getConfig("userId"))
      driver.findElement(By.id("pass")).sendKeys(getConfig("pass"))
      driver.findElement(By.id("submitButton")).click()

      val accountBalanceElement = new WebDriverWait(driver, 10).until(
        new ExpectedCondition[WebElement] {
          override def apply(d: WebDriver) = d.findElement(By.id("currentAccBalance"))
        })

      currentBalance = accountBalanceElement.getText.replace(',','.').toDouble
    }

    currentBalance
  }

  def getConfig(key: String): String = {
    val configNamespace: String = "app.services.mbank"
    val configKey: String = configNamespace + "." + key

    Play.current.configuration.getString(configKey).orNull
  }
} 
开发者ID:soomalx,项目名称:bigspender,代码行数:39,代码来源:MbankService.scala

示例10: RpcIntroTest

//设置package包名称以及导入依赖的类
package io.udash.web.guide.demos.rpc

import io.udash.web.SeleniumTest
import org.openqa.selenium.WebElement

class RpcIntroTest extends SeleniumTest {
  val rpcIntroUrl = "/#/rpc"

  "RpcIntro view" should {
    driver.get(server.createUrl(rpcIntroUrl))

    "contain two example buttons" in {
      eventually {
        driver.findElementById("ping-pong-call-demo")
        driver.findElementById("ping-pong-push-demo")
      }
    }

    "receive response in call demo" in {
      val callDemo = driver.findElementById("ping-pong-call-demo")
      buttonTest(callDemo)
    }

    "receive response in push demo" in {
      val pushDemo = driver.findElementById("ping-pong-push-demo")
      buttonTest(pushDemo)
    }
  }

  def buttonTest(callDemo: WebElement): Unit = {
    for (i <- 1 to 3) {
      callDemo.click()
      eventually {
        callDemo.isEnabled should be(true)
        callDemo.getText should be(s"Ping($i)")
      }
    }
  }
} 
开发者ID:UdashFramework,项目名称:udash-guide,代码行数:40,代码来源:RpcIntroTest.scala

示例11: RpcSerializationTest

//设置package包名称以及导入依赖的类
package io.udash.web.guide.demos.rpc

import java.util.concurrent.TimeUnit

import io.udash.web.SeleniumTest
import org.openqa.selenium.WebElement

class RpcSerializationTest extends SeleniumTest {
  val rpcFrontendUrl = "/#/rpc/serialization"

  "RpcSerialization view" should {
    driver.get(server.createUrl(rpcFrontendUrl))

    "contain example button" in {
      eventually {
        driver.findElementById("gencodec-demo")
      }
    }

    "receive msg from backend" in {
      val callDemo = driver.findElementById("gencodec-demo")

      callDemo.isEnabled should be(true)
      callDemo.click()

      eventually {
        driver.findElementById("gencodec-demo-int").getText shouldNot be(empty)
        driver.findElementById("gencodec-demo-double").getText shouldNot be(empty)
        driver.findElementById("gencodec-demo-string").getText shouldNot be(empty)
        driver.findElementById("gencodec-demo-seq").getText shouldNot be(empty)
        driver.findElementById("gencodec-demo-map").getText shouldNot be(empty)
        driver.findElementById("gencodec-demo-caseClass").getText shouldNot be(empty)
        driver.findElementById("gencodec-demo-cls-int").getText shouldNot be(empty)
        driver.findElementById("gencodec-demo-cls-string").getText shouldNot be(empty)
        driver.findElementById("gencodec-demo-cls-var").getText shouldNot be(empty)
        driver.findElementById("gencodec-demo-sealedTrait").getText shouldNot be(empty)
      }
    }
  }

  private def responseElement: WebElement = driver.findElementById("notifications-demo-response")
} 
开发者ID:UdashFramework,项目名称:udash-guide,代码行数:43,代码来源:RpcSerializationTest.scala

示例12: RpcFrontendTest

//设置package包名称以及导入依赖的类
package io.udash.web.guide.demos.rpc

import java.util.concurrent.TimeUnit

import io.udash.web.SeleniumTest
import org.openqa.selenium.By.ByTagName
import org.openqa.selenium.WebElement

class RpcFrontendTest extends SeleniumTest {
  val rpcFrontendUrl = "/#/rpc/server-client"

  "RpcFrontend view" should {
    driver.get(server.createUrl(rpcFrontendUrl))

    "contain example button" in {
      eventually {
        driver.findElementById("notifications-demo")
      }
    }

    "receive msg every second after registration" in {
      val callDemo = driver.findElementById("notifications-demo")

      callDemo.isEnabled should be(true)
      var responseText = responseElement.getText.stripPrefix("Last message: ")
      responseText.equalsIgnoreCase("-") should be(true)

      for (_ <- 1 to 3) {
        responseText = responseElement.getText
        callDemo.click()

        for (_ <- 1 to 3) eventually {
          responseElement.getText shouldNot be(responseText)
          responseText = responseElement.getText
        }

        callDemo.click()
        responseText = responseElement.getText

        for (_ <- 1 to 2) eventually {
          TimeUnit.SECONDS.sleep(2)
          responseElement.getText should be(responseText)
          responseText = responseElement.getText
        }
      }
    }
  }

  private def responseElement: WebElement = driver.findElementById("notifications-demo-response")
} 
开发者ID:UdashFramework,项目名称:udash-guide,代码行数:51,代码来源:RpcFrontendTest.scala

示例13: goOn

//设置package包名称以及导入依赖的类
package uk.gov.hmrc.softdrinksindustrylevyfrontend.util

import java.awt.Robot

import org.openqa.selenium.support.ui.{ExpectedCondition, ExpectedConditions, WebDriverWait}
import org.openqa.selenium.{By, WebDriver, WebElement}
import org.scalatest.concurrent.{Eventually, IntegrationPatience}
import org.scalatest.selenium.WebBrowser
import org.scalatest.{Assertions, Matchers}
import uk.gov.hmrc.softdrinksindustrylevyfrontend.generic.WebPage


trait NavigationSugar extends WebBrowser with Eventually with Assertions with Matchers with IntegrationPatience {

  val robot = new Robot()

  def goOn(page: WebPage)(implicit webDriver: WebDriver) = {
    goTo(page)
    on(page)
  }

  def on(page: WebPage)(implicit webDriver: WebDriver) = {
    val wait = new WebDriverWait(webDriver, 5)
    wait.until(ExpectedConditions.presenceOfElementLocated(By.tagName("body")))
    assert(page.isCurrentPage, s"Page was not loaded: ${page.currentUrl}")
  }

  def notOn(page: WebPage)(implicit webDriver: WebDriver) = {
    eventually {
      webDriver.findElement(By.tagName("body"))
    }
    assertResult(false, s"\nDid not expect ${page.currentUrl} to be loaded") {
      page.isCurrentPage
    }
  }

  def loadPage()(implicit webDriver: WebDriver) = {
    val wait = new WebDriverWait(webDriver, 15)
    wait.until(
      new ExpectedCondition[WebElement] {
        override def apply(d: WebDriver) = d.findElement(By.tagName("body"))
      }
    )
  }

  def anotherTabIsOpened()(implicit webDriver: WebDriver) = {
    webDriver.getWindowHandles.size() should be(2)
  }

  def browserGoBack()(implicit webDriver: WebDriver) = {
    webDriver.navigate().back()
  }

  def switchToTabWith(marker: => Boolean)(implicit webDriver: WebDriver): Any = {
    windowHandles.foreach { newTab: String =>
      switch to window(newTab)
      if (marker) return
    }
    fail(s"Marker evaluation resolves false for current page")
  }
} 
开发者ID:hmrc,项目名称:soft-drinks-industry-levy-frontend,代码行数:62,代码来源:NavigationSugar.scala

示例14: safeExecute

//设置package包名称以及导入依赖的类
package jesse.lee.ops

import jesse.lee.model.DOM
import org.openqa.selenium.{WebElement, By}
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.remote.RemoteWebDriver
import org.openqa.selenium.support.ui.Select


  def safeExecute[T](block: => T): Option[T] = try {
    Some(block)
  } catch {
    case e: Throwable => None
  }

  def convertDomElements(elements: java.util.List[WebElement]): Seq[DOM] = {
    import scala.collection.mutable

    var list = mutable.ListBuffer[DOM]()

    for (i <- 0 until elements.size()) {
      list += DOM(elements.get(i))
    }

    list.toList
  }
} 
开发者ID:wracker1,项目名称:ticket-booker,代码行数:28,代码来源:SeleniumOps.scala

示例15: DOM

//设置package包名称以及导入依赖的类
package jesse.lee.model

import jesse.lee.ops.SeleniumOps
import org.openqa.selenium.{By, WebElement}


case class DOM(element: WebElement) extends SeleniumOps {
  def text = element.getText
  def text(value: String) = element.sendKeys(value)
  def attribute(name: String) = element.getAttribute(name)
  def tagName = element.getTagName
  def click = element.click()
  def clear = element.clear()
  def sendKeys(keys: String) = element.sendKeys(keys)

  def findItem(by: By): Option[DOM] = safeExecute(DOM(element.findElement(by)))

  def findItems(by: By): Seq[DOM] = try {
    convertDomElements(element.findElements(by))
  } catch {
    case e: Throwable => Nil
  }

  def findItemByLinkText(text: String) = findItem(By.linkText(text))

  def findItemsWithCssSelector(css: String): Seq[DOM] = try {
    convertDomElements(element.findElements(By.cssSelector(css)))
  } catch {
    case e: Throwable => Nil
  }

  def selectOptionWithValue(value: String) = findItemsWithCssSelector("option").reverse.map { option =>
    if (option.attribute("value") == value) {
      option.click
    }
  }
} 
开发者ID:wracker1,项目名称:ticket-booker,代码行数:38,代码来源:DOM.scala


注:本文中的org.openqa.selenium.WebElement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。