by Lazy Sloth
Selenium Quick Start for Beginners
import logging
import uvicorn
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from fastapi.templating import Jinja2Templates
from selenium_utils import SeleniumUtility
URL_TO_FETCH = "https://www.example.com"
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
app = FastAPI()
templates = Jinja2Templates(directory="templates")
@app.get("/", response_class=HTMLResponse)
async def page_information():
selenium_util = SeleniumUtility()
title = (
selenium_util.get_page_title(URL_TO_FETCH) or "Failed to retrieve page title"
)
return templates.TemplateResponse("page_information.html", {"page_title": title})
Created: | Last Updated:
Introduction to the Selenium App Template
Welcome to the step-by-step guide on how to use the Selenium App template on Lazy. This template is designed for builders who need to automate web interactions such as end-to-end tests, functional tests, or web crawling with sophisticated steps like clicks and element interactions. By the end of this guide, you'll be able to deploy an app that uses Selenium to fetch and display the title of a web page.
Getting Started
To begin using this template, simply click on "Start with this Template" on the Lazy platform. This will pre-populate the code in the Lazy Builder interface, so you won't need to copy, paste, or delete any code.
Test: Deploying the App
Once you've started with the template, press the "Test" button. This will initiate the deployment of your app and launch the Lazy CLI. The deployment process is handled entirely by Lazy, so you don't need to worry about installing libraries or setting up your environment.
Using the App
After the app is deployed, Lazy will provide you with a dedicated server link. You can use this link to interact with your Selenium App. If you're using FastAPI, Lazy will also provide a docs link, which you can use to explore the API endpoints and their functionalities.
The main endpoint of your app will be the root ("/"), which, when accessed, will use Selenium to fetch the title of the specified URL and display it in a simple HTML page. When you visit the server link provided by Lazy, you should see the title of the web page specified in the code displayed on your screen.
Integrating the App
If you wish to integrate this app into another service or frontend, you may need to add the app's server link provided by Lazy to the external tool. For example, if you're creating a dashboard that displays information fetched by the Selenium App, you would insert the server link into your dashboard's configuration to display the fetched data.
Remember, all the necessary code and deployment configurations are already set up for you in the Lazy template. Your main focus will be on using the app and integrating it with other tools or services as needed.
If you have any questions or need further assistance, the Lazy customer support team is here to help you make the most out of your app-building experience.