Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7192619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:58:43+00:00 2026-05-28T19:58:43+00:00

We have a Selenium WebElement we’re getting from the Java API but we’ve created

  • 0

We have a Selenium WebElement we’re getting from the Java API but we’ve created a Scala class, Element, and mixin more specific traits (e.g. Clickable, Submittable, etc.).

Our method looks like:

toScalaElement(e : WebElement) = {
   e.type match { 
      case Input => new Element(e) with Submittable
      case Link  => new Element(e) with Clickable
      ...
      case _ => new Element
   }
}

The return type is always Element as that’s the root class of all the cases. However, we would like to retain the mixin traits when it is returned.

It was advised to look at builders in Scala’s Collections API but we’re unsure how that relates to this particular application. Obviously, if there’s a better way than traits mixins that solution will be appreciated.

Update: I changed the case to match against sub-types instead of Strings, but essence of question remains unchanged.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T19:58:44+00:00Added an answer on May 28, 2026 at 7:58 pm

    I don’t think it’s doable. The method as a whole needs to have a single return type. In case of builders, this return type is generic and so can be different between method calls, but the compilers needs arguments to have different types to choose the builder. It looks like this:

    case class WebElementConverter[T1, T2](f: T1 => T2) {
      def convert(e: T1) = f(e)
    }
    
    object WebElementConverter {
      implicit val inputConverter = WebElementConverter[Input, Element with Submittable](x => new Element(x) with Submittable)
      // other converters
    }
    
    def toScalaElement[T1 <: WebElement, T2 <: Element](e : T1)(implicit b: WebElementConverter[T1, T2]) = b.convert(e)
    

    And now you can get desired result here

    val i = new Input // same as val i: Input = new Input
    toScalaElement(i)
    

    but not here:

    val i: Element = new Input
    toScalaElement(i) // looks for an implicit WebElementConverter[Element, <some type>]
    

    So if the static type of e is just WebElement, builders don’t help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a the following selenium test suite inheriting from the same base class,
I have a suite of Selenium tests (created using Java in Selenium RC 1.0.3)
I have a Selenium WebElement selected, for example like this: WebElement element = webDriver.findElement(By.xpath('//div/span[@id='test']'));
I just wanted some opinions from people that have run Selenium ( http://selenium.openqa.org )
I have the following code: from selenium import selenium selenium = selenium(localhost, 4444, *chrome,
We are using Junit + Selenium to webtest our webpage. But we have run
I have a test method created using Selenium, something similar to this: [TestFixture] public
I have searched the Selenium Webdriver APi docs hosted on google code. Currently using
I'm using Selenium Java 2.0b3 . I have this code: ... WebDriver driver =
I have created a Selenium test using the Firefox Addon. Now, I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.