Bullshit free Monitoring Solution.
DSLExecutor User Guide
To effectively interact with web elements using the DSL commands, you need to understand how to locate elements on a webpage. This process is called “DOM selection,” and it is based on using selectors that uniquely identify HTML elements in the Document Object Model (DOM). Below, we explain common types of selectors that are used throughout the examples.
Selectors are the key to targeting elements on a webpage for actions like clicking, filling out forms, or verifying text. Here are some of the main types of selectors:
#id
)
#id_username
fill "#id_username" with "my_username"
id_username
with the value
my_username
..class
)
.btn-primary
click ".btn-primary"
btn-primary
.[attribute=value]
)
[type="checkbox"]
click "input[type=\"checkbox\"]"
checkbox
.a[href="/search/"]
a
) tag with
a specific href
attribute. This is helpful for selecting
links.click "a.nav-link[href=\"/search/\"]"
/search/
page.:nth-of-type()
)
.list-item:nth-of-type(2)
click ".list-item:nth-of-type(2)"
list-item
.>
)
div.container > button.btn-submit
click "div.container > button.btn-submit"
btn-submit
that is a direct child of a
div
with the class container
.+
)
label + input[type="text"]
click "label + input[type=\"text\"]"
^=
)
a[href^="https://example.com"]
click "a[href^=\"https://example.com\"]"
href
attribute starts with
https://example.com
.$=
)
img[src$=".png"]
click "img[src$=\".png\"]"
src
attribute ends with .png
.*=
)
button[class*='-primary']
click "button[class*='-primary']"
-primary
.To effectively automate interactions with a webpage, it is crucial to use the correct selector to uniquely identify elements. Here are some tips:
id
, use it, as IDs are unique within the page, ensuring
precise targeting.type
, name
, or
placeholder
.Selectors are based on the CSS (Cascading Style Sheets) selector syntax, which is a web standard defined by the World Wide Web Consortium (W3C). CSS selectors are not only used for styling purposes but also for selecting elements in JavaScript and automation frameworks like Playwright. The syntax and behavior of these selectors follow the rules set by the CSS Selectors Level 3 specification.
The DSL commands allow you to perform actions like filling forms, clicking buttons, and verifying content on a webpage. Below are examples of how to use each command.
Command:
fill "#id_username" with "my_username"
Explanation: This command fills the input field with
the selector #id_username
with the value
my_username
.
Command:
click ".btn-primary"
Explanation: This command clicks on an element with
the class .btn-primary
. This is commonly used for buttons
or links.
Command:
check-text "Welcome to the dashboard" is-present
Explanation: This command checks if the text “Welcome to the dashboard” is present on the current page. If the text is not found, an error will be logged.
Command:
assert element present "#logout-button"
Explanation: This command verifies that the element
with the selector #logout-button
is present on the
page.
Command:
get element content "table.table.table-striped"
Explanation: This command gets the inner content of
the table with the class table.table-striped
. This is
useful for capturing results or output from the webpage.
Command:
click "a.nav-link[href=\"/search/\"]"
Explanation: This command clicks on a link that
navigates to the search page. The selector targets an anchor tag with
the class nav-link
and an href
attribute of
/search/
.
Command:
fill "textarea.form-control.mb-3[name=\"query\"]" with "John Doe"
Explanation: This command fills a text area with the
name query
with the value “John Doe”. Text areas are often
used for larger inputs like comments or queries.
Command:
click "button.btn.btn-primary.my-2.my-sm-0[type=\"submit\"]"
Explanation: This command clicks a button that
submits a form. The selector targets a button with multiple classes and
a type of submit
.
Command:
check-text "Result" is-present
Explanation: This command verifies that the text “Result” is present on the page, indicating that the search results are displayed.
Command:
get element content "table.table.table-striped"
Explanation: This command captures the content of a
table with the class table.table-striped
. This is useful
for logging data from the webpage, such as search results or
reports.
Command:
click "#submit-button"
Explanation: This command clicks on an element with
the ID #submit-button
. IDs are unique within the page,
making this a precise way to target an element.
Command:
click "input[type=\"checkbox\"]"
Explanation: This command clicks on an input element
of type checkbox
. Attribute selectors are useful for
targeting elements with specific attributes.
Command:
fill "input[placeholder=\"Enter your name\"]" with "Jane Doe"
Explanation: This command fills an input field that has a placeholder text of “Enter your name” with the value “Jane Doe”. Placeholder attributes are commonly used for guiding users.
Command:
click ".list-item:nth-of-type(2)"
Explanation: This command clicks on the second
element with the class list-item
. Position selectors like
:nth-of-type()
help in selecting elements based on their
order.
Command:
check-text "Error" is-present in "div.alert-danger"
Explanation: This command checks if the text “Error”
is present within a specific element with the selector
div.alert-danger
. This is useful when the text needs to be
verified within a certain context.
Command:
assert element present "div.card.card-info"
Explanation: This command asserts the presence of a
div
element with multiple classes card
and
card-info
. This is helpful for targeting elements that
share multiple styles or categories.
Command:
get element content "div[data-status=\"active\"].user-info"
Explanation: This command gets the content of a
div
element with the attribute
data-status="active"
and the class user-info
.
This helps in targeting specific elements dynamically generated or
filtered by status.
Command:
click "div.container > button.btn-submit"
Explanation: This command clicks on a button with
the class btn-submit
that is a direct child of a
div
element with the class container
. Child
selectors help in targeting elements within a specific parent.
Command:
click "label + input[type=\"text\"]"
Explanation: This command clicks on an input element
of type text
that is immediately after a label
element. The +
selector is useful for selecting siblings
that are adjacent.
Command:
click "a[href^=\"https://example.com\"]"
Explanation: This command clicks on an anchor tag
(a
) where the href
attribute starts with
https://example.com
. The ^=
selector is useful
for partial matches at the beginning of an attribute value.
Command:
click "img[src$=\".png\"]"
Explanation: This command clicks on an
img
element where the src
attribute ends with
.png
. The $=
selector is used for matching
elements with attributes that end with a certain value.
Command:
click "button[class*='-primary']"
Explanation: This command clicks on a button element
where the class
attribute contains -primary
.
The *=
selector is useful for matching elements with an
attribute that contains a specific substring.
Command:
fill "form#login-form input[name=\"username\"]" with "admin"
Explanation: This command fills the input field
named username
inside a form with the ID
login-form
with the value admin
. Complex
selectors allow for precise targeting of elements in nested
structures.
Command:
assert element present "ul > li:first-child"
Explanation: This command asserts that the first
li
element within a ul
list is present.
Pseudo-classes like :first-child
are useful for targeting
specific positions within a group of elements.
Command:
click "div.container button.btn-success"
Explanation: This command clicks a button with the
class btn-success
that is a descendant of a
div
element with the class container
. The
descendant selector allows for targeting elements within a
hierarchy.
DSLExecutor Command Examples
Below are multiple examples for each command. These examples show different use cases of each command, using various selectors and scenarios to illustrate their versatility.
fill "#first_name" with "John"
fill "input[placeholder='Enter email']" with "john@example.com"
fill "input[type='password']" with "mySecurePassword"
fill "textarea.comment-box" with "This is my comment."
fill "#user_address" with "123 Main St."
fill "input[name='zip_code']" with "90210"
fill "input[data-id='username']" with "uniqueUser123"
fill "form#signup-form input[name='phone']" with "123-456-7890"
fill "input.contact-field" with "contact@example.com"
fill "textarea[rows='5']" with "This is a multiline text input."
click "button[type='submit']"
click ".btn.btn-primary"
click "#logout"
click "div.alert > a.close"
click "a[href='/profile']"
click "li.menu-item:nth-of-type(3)"
click "span.icon-refresh"
click "input[type='checkbox']"
click "#save-button"
click "nav.main-menu a[href='/settings']"
check-text "Login successful" is-present
check-text "User not found" is-present
check-text "Welcome, John!" is-present
check-text "Payment completed" is-present
check-text "Error: invalid credentials" is-present
check-text "Your cart is empty" is-present
check-text "Profile updated successfully" is-present
check-text "Terms and Conditions" is-present
check-text "404 - Page Not Found" is-present
check-text "Subscription confirmed" is-present
assert element present "#profile-picture"
assert element present "div.container"
assert element present "input[type='submit']"
assert element present "ul > li:first-child"
assert element present "div#footer .social-links"
assert element present "form.contact-form"
assert element present "nav .menu-item.active"
assert element present "button[disabled]"
assert element present "header > h1.site-title"
assert element present "div.modal[role='dialog']"
get element content "table.data-table"
get element content "div#main-content"
get element content "span.price-tag"
get element content "p.description-text"
get element content "h1.page-title"
get element content "ul.list-items > li:nth-child(2)"
get element content "section#about-us"
get element content "a[href='/contact']"
get element content "footer .address"
get element content "div.alert-message"
click "a[data-toggle='dropdown']"
click "input[aria-label='Search']"
click "button[title='Save Changes']"
click "div[role='alert']"
click "li[data-active='true']"
click "img[alt='Product Image']"
click "button[aria-expanded='false']"
click "input[required]"
click "select[name='country']"
click "a[target='_blank']"
fill "input[placeholder='Full Name']" with "Jane Doe"
fill "input[placeholder='Enter your password']" with "safePassword123"
fill "textarea[placeholder='Leave your comment here']" with "Great product!"
fill "input[placeholder='Search']" with "Django tutorials"
fill "input[placeholder='Email address']" with "jane@example.com"
fill "input[placeholder='Phone Number']" with "1234567890"
fill "textarea[placeholder='Describe your issue']" with "The app crashes on login."
fill "input[placeholder='Username']" with "jane_doe"
fill "input[placeholder='ZIP code']" with "12345"
fill "input[placeholder='Confirm Password']" with "safePassword123"
click "div.container > button.submit"
click "ul.list > li.item:first-child"
click "div.card > a.read-more"
click "form#signup-form > input[type='text']"
click "section.news > article:first-child"
click "nav.menu > ul > li:nth-child(2)"
click "div.panel > button.toggle"
click "div.wrapper > a.link"
click "header > nav > ul > li:last-child"
click "div.row > div.col-md-6 > button.buy-now"