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

  • SEARCH
  • Home
  • 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 6209885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:03:50+00:00 2026-05-24T06:03:50+00:00

While using Selenium 2, I have following statements scattered in test methods – driver.findElement(By.name(usernameBox)).sendKeys(userEmailAddress);

  • 0

While using Selenium 2, I have following statements scattered in test methods –

 driver.findElement(By.name(usernameBox)).sendKeys(userEmailAddress);

I think of abstracting them in static methods of a WebUtil class –

 public class WebUtils {

    public static void type(WebDeriver driver, String locator, String testData) {
         driver.findElement(By.name(locator)).sendKeys(testData);

    }
 }

And the method call would be –

  WebUtils.type(driver, usernameBox, userEmailAddress);

Could I improve it more, for example if I could avoid passing driver object every time, or some thing more?

  • 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-24T06:03:51+00:00Added an answer on May 24, 2026 at 6:03 am

    I would suggest you extend the base class that you generally use and add your extension methods there.

    here is an example to extend Selenium class.

    public class MySelenium : WebDriverBackedSelenium
    {
            public IWebDriver Driver { get; set; }
    
            public ISelenium Selenium { get; set; }
    
    
            public MySelenium(IWebDriver baseDriver, string baseUrl)
                : base(baseDriver, baseUrl)
            {
                Driver = baseDriver;
            }
    
            public MySelenium(IWebDriver baseDriver, Uri baseUrl)
                : base(baseDriver, baseUrl) { }
    
            public static void type(String locator, String testData) {
             Driver.findElement(By.name(locator)).sendKeys(testData);
    
        }
    

    }

    You initialize it as follows in a common class that is used by all your tests:

    var driver =GetDriver(); //method to initialize driver
    Selenium= new MySelenium(driver,baseUrl);    //Selenium is a protected variable accessible from your tests
    

    Now you invoke type as follows:

     Selenium.type(userNameBox,"username");
    

    P.S: Srry the above code is in c# but you can port it over to java..

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

Sidebar

Related Questions

I have been using Selenium a lot lately (testing an ExtJs app) and while
While attempting to access a test portal, I'm encountering the following problem while using
while using the following constructor $this->pdo = new PDO ($this->source, $this->username, $this->password); if I
I am trying to capture screenshots on test failure using selenium-client and rspec. I
while using tiles along with spring i m getting following error: java.net.UnknownHostException: tiles.apache.org program
I'm using Selenium to ease my testing burden and I have about 1,000 different
I'm using Selenium RC with chrome-mode for Firefox to automate test cases for a
I have been using Cucumber and Webrat for a while. I now need to
I am using Selenium to do testing, We write our test cases in HTML
I recorded an action using the Selenium IDE and used the File->Export Test Cases

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.