Simple robot
Get the code and run this example in your favorite editor on our Portal!
This simple Robot Framework robot opens a web page, stores some text content, and takes a screenshot of an image element on the web page.
The robot written in Robot Framework
This version of the robot (tasks.robot
) uses Robot Framework syntax:
# ## Simple web scraper robot
# Opens a web page and stores some content.
*** Settings ***
Documentation A simple web scraper robot.
... Opens a website.
... Stores the web page text in a file in the output directory.
... Saves a screenshot of an element in the output directory.
Library RPA.Browser.Selenium
Library RPA.FileSystem
*** Variables ***
${URL}= https://robotframework.org/
*** Tasks ***
Store Web Page Content
Open Available Browser ${URL}
${text}= Get Text scroller
Create File
... ${CURDIR}${/}output${/}text.txt
... ${text}
... overwrite=True
Screenshot
... css:.img-fluid
... ${CURDIR}${/}output${/}screenshot.png
[Teardown] Close Browser
The robot written in Python
For comparison, this is the same robot written in Python (tasks.py
):
from RPA.Browser.Selenium import Selenium
from RPA.FileSystem import FileSystem
browser = Selenium()
file_system = FileSystem()
url = "https://robotframework.org/"
def store_web_page_content():
browser.open_available_browser(url)
text = browser.get_text("scroller")
file_system.create_file("output/text.txt", text, overwrite=True)
browser.screenshot("css:.img-fluid", "output/screenshot.png")
def main():
try:
store_web_page_content()
finally:
browser.close_all_browsers()
if __name__ == "__main__":
main()
Learn more about the libraries mentioned on this page: