Open In App

How To Automate Google Chrome Using Foxtrot and Python

Last Updated : 04 Jun, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we are going to see how to automate google chrome using Foxtrot & Python.

What is Foxtrot RPA?

Robotic process automation (RPA) cuts down employees’ workloads by automating repetitive, high-volume steps in processes. Software robots, such as Foxtrot RPA emulate the actions of human workers to execute tasks within applications via their UI.

Prerequisites :

  • Install the latest version of Foxtrot RPA.
  • Install python selenium package by running the following command in terminal.
  • Install the latest Google Chrome and its Chrome webdriver.

We need to create a simple python script that automates a work in Google Chrome using selenium and chrome webdriver. And here, we will automate an authorization at “https://auth.geeksforgeeks.org” and extract the Name, Email, Institute name from the logged-in profile.

First, we test it by running the python file and then we will add this python script in Foxtrot Python Actions Botflow and run the Botflow.

Extracting information using webdriver:

First, we need to initiate the webdriver using selenium and send a get request to the url, and then identify the HTML document and find the input tags and button tags which accept username/email, password, and sign in button.

To Send the user given email and password to the input tags respectively:

driver.find_element_by_name('user').send_keys(email)
driver.find_element_by_name('pass').send_keys(password)

To Identify the button tag and click on it using the CSS selector via selenium webdriver:

driver.find_element_by_css_selector(‘button.btn.btn-green.signin-button’).click()

After clicking on Sign in, a new page should be loaded containing the Name, Institute Name, and Email id.

Identify the tags containing the above data’s and select them:

container = driver.find_elements_by_css_selector(‘div.mdl-cell.mdl-cell–9-col.mdl-cell–12-col-phone.textBold’)

Get the text from each of these tags from the returned list of selected CSS selectors:

name = container[0].text
try:
institution = container[1].find_element_by_css_selector('a').text
except:
institution = container[1].text
email_id = container[2].text

Finally, print the output:

print({“Name”: name, “Institution”: institution, “Email ID”: email})

Below is the implementation:

Python
# Import the required modules
from selenium import webdriver
import time

# Main Function
if __name__ == '__main__':

    # Provide the email and password
    email = ''
    password = ''

    options = webdriver.ChromeOptions()
    options.add_argument("--start-maximized")

    # Provide the path of chromedriver
    # present on your system.
    driver = webdriver.Chrome(
        executable_path="C:/chromedriver/chromedriver.exe", 
      chrome_options=options)
    driver.set_window_size(1920, 1080)

    # Send a get request to the url
    driver.get('https://auth.geeksforgeeks.org/')
    time.sleep(5)

    # Finds the input box by name
    # in DOM tree to send both
    # the provided email and password in it.
    driver.find_element_by_name('user').send_keys(email)
    driver.find_element_by_name('pass').send_keys(password)

    # Find the signin button and click on it.
    driver.find_element_by_css_selector(
        'button.btn.btn-green.signin-button').click()
    time.sleep(5)

    # Returns the list of elements
    # having the following css selector.
    container = driver.find_elements_by_css_selector(
        'div.mdl-cell.mdl-cell--9-col.mdl-cell--12-col-phone.textBold')

    # Extracts the text from name,
    # institution, email_id css selector.
    name = container[0].text
    try:
        institution = container[1].find_element_by_css_selector('a').text
    except:
        institution = container[1].text
    email_id = container[2].text

    # Output
    print({"Name": name, "Institution": institution,
           "Email ID": email})

    # Quits the driver
    driver.quit()

Output:

Automating the Script using Foxtrot

Here we are going to automate the script using foxtrot.

Step 1: Open Foxtrot App and make sure to select the Level as Expert in Account setting:

Step 2: Create a New Botflow and click on the Advanced tab in Actions Panel and select Python.

Step 3: A new window should appear where you can select the method as Code and copy-paste the previous script in the Code Box provided.

Or, you can select the method the python file containing the script:

Step 4: To show the output of the above script in Foxtrot, we need to create a variable. Click on the checkbox beside Save to and select the magic button on the right side.

Creating Variable

Step 5: A new window should appear called Expression, Select Variables in the Items and click on “+” button top right of the window.

Step 6: Provide a Name and select Type as Text and click OK.

Click OK again and then type the name of the variable in Save To Box. The below Image represents the final state after following the above-mentioned steps.

Click on OK to Run the BOT:

Step 7: To view the Output, Select Variables in the BotFlow and click on the pencil button of the previously selected variable.

The output is the same as we saw before while running the script on Terminal:

foxout-copy-2


This is how we can automate Google Chrome by using Selenium, Python and Foxtrot.



Previous Article
Next Article

Similar Reads

Automate Chrome Dino Game using Python
For this article, we will be building a Python bot that can play the "Chrome Dino Offline Game". Chrome dino is a dinosaur game that launches itself on your web browser when there is no internet connection. For the introduction of the game, the dinosaur has to jump to avoid the approaching cactus or duck to avoid the bird. The first fundamental ste
7 min read
Python | Automate Google Search using Selenium
Google search can be automated using Python script in just 2 minutes. This can be done using selenium (a browser automation tool). Selenium is a portable framework for testing web applications. It can automatically perform the same interactions that any you need to perform manually and this is a small example of it. Mastering Selenium will help you
3 min read
How to Automate Google Sheets with Python?
In this article, we will discuss how to Automate Google Sheets with Python. Pygsheets is a simple python library that can be used to automate Google Sheets through the Google Sheets API. An example use of this library would be to automate the plotting of graphs based on some data in CSV files that we can export to Google Sheets. So, let’s proceed f
4 min read
Automate linkedin connections using Python
LinkedIn connections are a very important thing for an IT professional, so we need to send connection requests to a lot of people who can be useful to us. But sometimes sending connection requests one at a time can be a little annoying and hectic. It would be nice to automate this work but How? Python to rescue!In this article, we will learn how to
3 min read
Automate getter-setter generator for Java using Python
Encapsulation is defined as the wrapping up of data under a single unit. Encapsulation can be achieved by declaring all the variables in the class as private and writing public methods in the class to set and get the values of variables. These public methods are called getters and setters. In practice, it is quite a time consuming and repetitive pr
3 min read
Automate Instagram Messages using Python
In this article, we will see how to send a single message to any number of people. We just have to provide a list of users. We will use selenium for this task. Packages neededSelenium: It is an open-source tool that automates web browsers. It provides a single interface that lets you write test scripts in programming languages like Ruby, Java, Node
6 min read
How to Automate VPN to change IP location on Ubuntu using Python?
To Protect Our system from unauthorized users Access you can spoof our system's IP Address using VPN service provided by different organizations. You can set up a VPN on your system for free. After you set up and log in to the VPN over the Ubuntu system you need to manually connect with different VPN servers after some duration. We can automate it
3 min read
How to Automate the Storage using Dropbox API in Python ?
In this Data Era Storing, Managing, and organizing the Data is an important factor considered by every business. Dropbox is one of the most popular cloud storage systems on the market, and it continues to improve its features. In this article, we will be demonstrating how one can connect to dropbox API using Python and perform Storage Automation ef
2 min read
Automate WhatsApp Messages With Python using Pywhatkit module
We can automate a Python script to send WhatsApp messages. In this article, we will learn the easiest ways using pywhatkit module that the website web.whatsapp.com uses to automate the sending of messages to any WhatsApp number. Installing pywhatkit module: pywhatkit is a python module for sending Whatsapp messages at a certain time. To install the
4 min read
Google Chrome Dino Bot using Image Recognition | Python
What would you see in your Chrome browser when there is no internet connection? Yes, everybody knows that dinosaur game that comes on screen. So, in this article, we are going to build a simple python bot that plays Chrome Dino Game without user interaction. Here we are not using any machine learning or artificial intelligence to counter this probl
4 min read