Installation
Element capture is a fundamental feature of TestStudio's Page Object Builder that allows you to identify and store web elements for use in your test scripts.
Using the Element Capture Extension
TestStudio's browser extension makes element capture simple and intuitive. With a single click, you can capture any element on a web page and store it as part of your page object.
Installation
Install the TestStudio browser extension from the Chrome Web Store or Firefox Add-ons marketplace. Once installed, you'll see the TestStudio icon in your browser toolbar.
Capturing Elements
To capture an element, follow these steps:
- Open the web page you want to test
- Click the TestStudio extension icon
- Enable element capture mode
- Click on the element you want to capture
- The element will be added to your page object
// Connect to TestStudio
const studio = new TestStudio.PageObjectBuilder();
// Start capture session
studio.startCapture("LoginPage");
// Elements will be captured via the browser extension
// and automatically added to your page object
// Result:
{
"name": "LoginPage",
"elements": [
{ "name": "usernameField", "selector": "#username" },
{ "name": "passwordField", "selector": "#password" },
{ "name": "loginButton", "selector": ".login-btn" }
]
}
Selector Strategies
TestStudio automatically generates the most reliable selector for each element, but you can also customize the selector strategy. The available strategies are:
- ID: Uses the element's ID attribute (most reliable)
- CSS: Uses CSS selectors
- XPath: Uses XPath expressions (most flexible)
- Text: Finds elements by their text content
- Name: Uses the element's name attribute
You can change the selector strategy for an element by editing it in the Page Object Builder interface.
Best Practices
For the most reliable element capture, follow these best practices:
- Prefer elements with stable IDs or unique class names
- Avoid capturing elements with dynamic attributes
- Use descriptive names for your elements
- Group related elements into logical page objects
- Verify captured elements by running a simple test
Following these best practices will ensure that your tests are reliable and maintainable.
Was this documentation helpful?