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


Scala By类代码示例

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


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

示例4: 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

示例5: 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

示例6: 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

示例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:Bii03,项目名称:students-clustering,代码行数:37,代码来源:PasswordResetPage.scala

示例8: 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

示例9: Parser

//设置package包名称以及导入依赖的类
package com.yukimt.scrape
package element

import org.openqa.selenium.{By, WebDriver}
import collection.JavaConversions._

class Parser(driver: WebDriver) {
  def getFirst(method:ParserMethod): HtmlElement = method(driver).head
  def tryFirst(method:ParserMethod): Option[HtmlElement] = {
    try {
      method(driver).headOption
    } catch {
      case e: Throwable =>
        println(e.getMessage)
        None
    }
  }
  def getAll(method:ParserMethod): Iterable[HtmlElement] = method(driver)
  def >>(method:ParserMethod) = getFirst(method)
  def >?>(method:ParserMethod) = tryFirst(method)
  def >>>(method:ParserMethod) = getAll(method)
}

object ParserMethod{
  def by(b: By): ParserMethod = {
    val method = (_b: By, driver: WebDriver) =>
      driver.findElements(_b).map(e => new HtmlElement(e, driver))
    method(b, _)
  }

  def css(cssQuery: String): ParserMethod = {
    val method = (query: String, driver: WebDriver) =>
      driver.findElements(By.cssSelector(query)).map(e => new HtmlElement(e, driver))
    method(cssQuery, _)
  }
} 
开发者ID:yuki-mt,项目名称:scraper4s,代码行数:37,代码来源:Parser.scala


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