RPA / Robocorp

Browsing / Webpages: open

Open a web page

tasks.py
Copied!

from robocorp.tasks import task
from robocorp import browser

@task
def open_webpage():
    """
    Open a web page with default configuration.
    """
    # Open a browser with the default configuration
    page = browser.goto("https://smartworkmaster.com/")

    # Perform actions on the page if needed
    # For example:
    # - Read text content
    text = page.locator("h1").text_content()
    print(f"Found page title: {text}")

    # - Take a screenshot
    page.screenshot(path="screenshot.png")

Open multiple tabs

tasks.py
Copied!

from robocorp.tasks import task
from robocorp import browser

@task
def open_multiple_tabs():
    """
    Open multiple browser tabs and work with them.
    """
    # Open the first tab
    browser_instance = browser.context()
    page1 = browser_instance.new_page()
    page1.goto("https://smartworkmaster.com/")

    # Open a second tab
    page2 = browser_instance.new_page()
    page2.goto("https://robocorp.com/")

    # Open a third tab
    page3 = browser_instance.new_page()
    page3.goto("https://github.com/")

    # Switch back to the first tab (context keeps track of all pages)
    page1.bring_to_front()

    # Do something on the first tab
    print(f"Title of first tab: {page1.title()}")

    # Switch to the second tab
    page2.bring_to_front()

    # Do something on the second tab
    print(f"Title of second tab: {page2.title()}")