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 8956315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T14:45:47+00:00 2026-06-15T14:45:47+00:00

I’m following the Page Object pattern suggested by Selenium, but how would I create

  • 0

I’m following the Page Object pattern suggested by Selenium, but how would I create a more specialized WebElement for a page. Specifically, we have tables on our pages and I have written some helper functions to get specific rows of a table, return the contents of a table, etc.

Currently, here is a snippet of a page object I created that has a table:

public class PermissionsPage  {

    @FindBy(id = "studyPermissionsTable")
    private WebElement permissionTable;

    @FindBy(id = "studyPermissionAddPermission")
    private WebElement addPermissionButton;

    ... 

}

So, what I’d like to do is have that permissionsTable to be a more customized WebElement that has some of those methods I mentioned earlier.

For example:

public class TableWebElement extends WebElement {
    WebElement table;
    // a WebDriver needs to come into play here too I think

    public List<Map<String, String>> getTableData() {
        // code to do this
    }

    public int getTableSize() {
        // code to do this
    }

    public WebElement getElementFromTable(String id) {
        // code to do this
    }
}

I hope that this makes sense what I’m trying to explain. I guess what I’m looking for is a way to have this custom WebElement to do some additional stuff that’s table-specific. Add this custom element to a Page and take advantage of the way Selenium wires the webelements to the page based on the annotations.

Is it possible? And if so, does anyone know how this can be done?

  • 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-06-15T14:45:49+00:00Added an answer on June 15, 2026 at 2:45 pm

    I created an interface that combines all of the WebDriver interfaces:

    public interface Element extends WebElement, WrapsElement, Locatable {}
    

    It’s just there to wrap up all of the things WebElements can do when wrapping an element.

    Then an implementation:

    public class ElementImpl implements Element {
    
        private final WebElement element;
    
        public ElementImpl(final WebElement element) {
            this.element = element;
        }
    
        @Override
        public void click() {
            element.click();
        }
    
        @Override
        public void sendKeys(CharSequence... keysToSend) {
            element.sendKeys(keysToSend);
        }
    
        // And so on, delegates all the way down...
    
    }
    

    Then, for example a check box:

    public class CheckBox extends ElementImpl {
    
        public CheckBox(WebElement element) {
            super(element);
        }
    
        public void toggle() {
            getWrappedElement().click();
        }
    
        public void check() {
            if (!isChecked()) {
                toggle();
            }
        }
    
        public void uncheck() {
            if (isChecked()) {
                toggle();
            }
        }
    
        public boolean isChecked() {
            return getWrappedElement().isSelected();
        }
    }
    

    When using it in my script:

    CheckBox cb = new CheckBox(element);
    cb.uncheck();
    

    I’ve also come up with a way of wrapping the Element classes. You have to create a few factories to replace the built-in PageFactory, but it is doable, and it lends a lot of flexibility.

    I’ve documented this process over on my site:

    • Wrapping WebElement: Part 1
    • Wrapping WebElement: Part 2

    I’ve also got a project called selophane that was inspired by this and other questions: selophane

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but

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.