Skip to content
Related Articles

Related Articles

Improve Article

How To Automate Google Chrome Using Foxtrot and Python

  • Last Updated : 14 Sep, 2021

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.

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

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:

Python3




# 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:

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




My Personal Notes arrow_drop_up
Recommended Articles
Page :