Actions

Actions are the primary way to interact with the page. The current available actions are goto, click, type, press_enter, exists, scroll, and wait.

We used the goto and wait actions in the Sessions example. In the following example, we display the click, type, press_enter, and exists actions.

search_amazon.py
from simplex import Simplex

simplex = Simplex(api_key="your_api_key")

def amazon_search(search_query):
    simplex.goto("amazon.com")
    simplex.click('the search bar')
    simplex.type(search_query)
    simplex.press_enter()
    simplex.click("the first search result")
    exists, reasoning = simplex.exists("One time purchase radio button")
    if exists:
        print(f"Found one time purchase radio button: {reasoning}")
        simplex.click("One time purchase radio button")
    simplex.click("Add to Cart")

amazon_search("premier protein shake")
amazon_search("lawnmower")

In the first search for protein shakes, we find a “One time purchase” radio button, while in the second search for a lawnmower, we only see a “Buy new” section. exists helps us manage these two different cases.

Extractors

Simplex currently provides one extractor — extract_text.

extract_text.py
from simplex import Simplex

simplex = Simplex(api_key="your_api_key")
simplex.goto("github.com/mitchellh")
num_contribs = simplex.extract_text("number of contributions")
print(num_contribs)
# Output: 5,145 contributions in the last year

This will extract the number of contributions from Mitchell’s GitHub profile.

That’s a lot of contributions!