Skip to main content

Using Smart Parameters

Smart Parameters allow you to interact with web pages using natural language. This powerful feature bridges the gap between technical precision and human-readable commands, making your automation scripts more maintainable and intuitive.

What You'll Learn​

  • What Smart Parameters are (technical selectors vs. natural language)
  • How Smart Parameters interpret your input
  • Examples of using both technical selectors and natural language
  • How Smart Parameters apply to URLs and key presses
  • The benefits of using Smart Parameters
  • Best practices for effective use

What Are Smart Parameters?​

Smart Parameters are context-aware values that intelligently determine what you're trying to target on a webpage. There are two ways to use Smart Parameters:

  1. Technical Selectors: Traditional CSS, XPath, or data-attribute selectors
  2. Natural Language Descriptions: Human-readable descriptions of elements

How Smart Parameters Work​

When you provide a Smart Parameter, the system:

  1. Analyzes whether you've provided a technical selector or natural language
  2. For technical selectors: Uses it directly to find the element
  3. For natural language: Translates your description into an appropriate selector
  4. Validates the element exists in the current page context
  5. Performs the requested action on the matched element

Smart Parameters in Action​

Using Technical Selectors​

Technical selectors provide precise control when you know the exact element structure:

# Using CSS Selector
browser.click(selector="#submit-button")

# Using XPath
browser.type(selector="//input[@name='username']", text="testuser")

Using Natural Language​

Natural language makes your code more readable and resilient to UI changes:

# Finding by visible text
browser.click("Sign In")

# Finding by element description
browser.type("Email field", "user@example.com")

# Finding by positional description
browser.click("Submit button in the login form")

URLs and Keys​

In addition to selectors, Smart Parameters can also handle things like URLs and keyboard keys.

For instance, I can navigate to a URL using a natural language description:

browser.navigate("google")

Which is equivalent to using a URL:

browser.navigate("https://www.google.com")

Similarly, when using the press function, you can specify keys loosely:

browser.press("return")

Is the same as saying:

browser.press("Enter")

Smart Parameter Commands​

Smart Parameters work with all interaction commands:

CommandExample with Technical SelectorExample with Natural Language
clickbrowser.click("#btn", wait="auto")browser.click("Sign up", wait="auto")
type_textbrowser.type_text(".input", "hello", delay=0.1)browser.type_text("Username field", "testuser", delay=0.1)
pressbrowser.press("Enter", wait="auto")browser.press("return key", wait="auto")
drag_and_dropbrowser.drag_and_drop("#source", "#target")browser.drag_and_drop("the blue block", "the thing that says 'droppable'")
navigatebrowser.navigate("https://www.example.com")browser.navigate("Example website")

Benefits of Smart Parameters​

  1. Readability: Natural language makes code self-documenting
  2. Maintainability: Less brittle than hard-coded selectors/parameters
  3. Flexibility: Choose the right approach for each scenario
  4. Productivity: Faster script creation with natural descriptions
  5. Resilience: Handles UI changes gracefully
  6. Accessibility: Easier for non-technical team members to understand
  7. Consistency: Promotes uniformity across automation scripts

Best Practices​

  1. Be specific with natural language descriptions:

    # Too vague
    browser.click("button") # May find multiple buttons

    # Better
    browser.click("Add to cart button")
  2. Consider element context:

    # Target elements within specific containers
    browser.type("Email field in the newsletter form", "news@example.com")

Conclusion​

Smart Parameters are a game-changer for web automation, offering a powerful yet user-friendly way to interact with web pages. By combining technical precision with natural language descriptions, you can create robust, readable scripts that adapt to changing UIs with ease.