Skip to content

xdev-software/selenium-elements

Repository files navigation

Latest version Build Quality Gate Status

Elements for Selenium

Define Selenium HTML elements as Java classes, similar to Selenium's @FindBy annotation.

Also contains a ton of other predefined utility, for example:

  • Automatically scrolling elements that perform operations into the view
  • Safe click: When an element is detected as stale a JavaScript click is executed instead
  • Option to globally wait until the page finished loading
  • Waiting for some time until the element is present (waitUntil)

Overall this should result in:

  • Less flaky tests
  • Abstraction of elements in an object oriented way

Usage

  1. Define the elements you want to access
    @FindBySelector(tagName = "body")
    abstract class BodyElement implements ImprovedWebElement {
        public MyElement myElement() {
            return waitForFirst(MyElement.class);
        }
    }
    
    @FindBySelector(id = "abc")
    abstract class MyElement implements ImprovedWebElement {
    }
  2. Utilize the predefined methods and classes to get/access the elements in a test
    class MyWebDriverTest implements CanFindElements {
        WebDriver webDriver;
    
        @BeforeEach
        void beforeEach() {
            webDriver = createWebDriver();
            CustomizableRemoteWebElementInstaller.install(
                webDriver,
                () -> new ImprovedRemoteWebElement(
                    "return document.readyState == 'complete';")
            );
        }
    
        @Test
        void test() {
            MyElement myElement = waitForFirst(BodyElement.class).myElement();
            assertEquals("Hello world", myElement.getText());
    
            // Or alternatively
            ElementInstantiatorInstance.instance().find(webDriver, BodyElement.class);
        }
    
        @AfterEach
        void afterEach() {
            // Stop webDriver here...
            webDriver = null;
        }
    
        @Override
        public WebDriver getWebDriver() {
            return webDriver;
        }
    }

You can also checkout the integrated tests to see this in action.

Installation

Installation guide for the latest release

Support

If you need support as soon as possible and you can't wait for any pull request, feel free to use our support.

Contributing

See the contributing guide for detailed instructions on how to get started with our project.

Dependencies and Licenses

View the license of the current project or the summary including all dependencies

Disclaimer: This is not an official Testcontainers/Selenium product and not associated

About

Define Selenium HTML elements as Java classes and access them easily

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Contributors 6

Languages