Automating Google meet using selenium in Python - GeeksforGeeks

13 Jan, 2022
Prerequisites: Selenium Python basics, Browser Automation using Selenium
Selenium is a powerful tool for controlling web browsers through programs and performing browser automation. It is functional for all browsers, works on all major OS and its scripts are written in various languages i.e Python, Java, C#, etc, we will be working with Python.
Selenium can be used to automate the web browser. In this article, we will learn how to sign in the Google account and join a meeting through Google meet with camera and microphone turned off using selenium.
The selenium module can be installed using the below command:
pip install selenium
Step 1: Import modules
Python3
# import required modulesfrom selenium import webdriverfrom selenium.webdriver.chrome.options import Optionsimport time
Step 2: Create an instance of Chrome browser with some required prerequisite Chrome Options().
Python3
# creating chrome instanceopt = Options()opt.add_argument('--disable-blink-features=AutomationControlled')opt.add_argument('--start-maximized')opt.add_experimental_option("prefs", {     "profile.default_content_setting_values.media_stream_mic": 1,    "profile.default_content_setting_values.media_stream_camera": 1,    "profile.default_content_setting_values.geolocation": 0,    "profile.default_content_setting_values.notifications": 1})driver = webdriver.Chrome(options=opt)
Step 3: Go to Google meet using this command
Python3
# go to google meetdriver.get('https://meet.google.com/xby-zehb-ncf')
Step 4: Calling the below function will turn off the camera and the microphone. In this function, turnOffMicCam(), we find the microphone & camera buttons by their xpaths using a function in selenium named find_element_by_xpath().
Python3
# explicit function to turn off mic and camdef turnOffMicCam():     # turn off Microphone    time.sleep(2)    driver.find_element_by_xpath(        '//*[@id="yDmH0d"]/c-wiz/div/div/div[8]/div[3]/div/div/div[2]/div/div[1]/div[1]/div[1]/div/div[4]/div[1]/div/div/div').click()    driver.implicitly_wait(3000)     # turn off camera    time.sleep(1)    driver.find_element_by_xpath(        '//*[@id="yDmH0d"]/c-wiz/div/div/div[8]/div[3]/div/div/div[2]/div/div[1]/div[1]/div[1]/div/div[4]/div[2]/div/div').click()    driver.implicitly_wait(3000)
Step 5: Below function would help us join the meeting at Google meet. In this function, joinNow(), we find the join now button by its css selector using a function in selenium named find_element_by_css_selector() and click it to join the meeting! (we do the same in AskToJoin() function).
Python3
def AskToJoin():    # Ask to Join meet    time.sleep(5)    driver.implicitly_wait(2000)    driver.find_element_by_css_selector(        'div.uArJ5e.UQuaGc.Y5sE8d.uyXBBb.xKiqt').click()    # Ask to join and join now buttons have same xpaths
Step 6: Below is the function that would log in the Google account using the credentials provided. In this function, Glogin(mail,pw), we find the email text box by its id using a function in selenium named find_element_by_id() and type in the email using send_keys() & click next button again using its id and find password text box using its xpath, type in the password using send_keys & again click login using its id
Python3
def Glogin(mail_address, password):    # Login Page    driver.get(        'https://accounts.google.com/ServiceLogin?hl=en&passive=true&continue=https://www.google.com/&ec=GAZAAQ')     # input Gmail    driver.find_element_by_id("identifierId").send_keys(mail_address)    driver.find_element_by_id("identifierNext").click()    driver.implicitly_wait(10)     # input Password    driver.find_element_by_xpath(        '//*[@id="password"]/div[1]/div/div[1]/input').send_keys(password)    driver.implicitly_wait(10)    driver.find_element_by_id("passwordNext").click()    driver.implicitly_wait(10)     # go to google home page    driver.get('https://google.com/')    driver.implicitly_wait(100)
Below is the complete program based on the above step-wise approach:
Python3
# import required modulesfrom selenium import webdriverfrom selenium.webdriver.chrome.options import Optionsimport time  def Glogin(mail_address, password):    # Login Page    driver.get(        'https://accounts.google.com/ServiceLogin?hl=en&passive=true&continue=https://www.google.com/&ec=GAZAAQ')     # input Gmail    driver.find_element_by_id("identifierId").send_keys(mail_address)    driver.find_element_by_id("identifierNext").click()    driver.implicitly_wait(10)     # input Password    driver.find_element_by_xpath(        '//*[@id="password"]/div[1]/div/div[1]/input').send_keys(password)    driver.implicitly_wait(10)    driver.find_element_by_id("passwordNext").click()    driver.implicitly_wait(10)     # go to google home page    driver.get('https://google.com/')    driver.implicitly_wait(100)  def turnOffMicCam():    # turn off Microphone    time.sleep(2)    driver.find_element_by_xpath(        '//*[@id="yDmH0d"]/c-wiz/div/div/div[8]/div[3]/div/div/div[2]/div/div[1]/div[1]/div[1]/div/div[4]/div[1]/div/div/div').click()    driver.implicitly_wait(3000)     # turn off camera    time.sleep(1)    driver.find_element_by_xpath(        '//*[@id="yDmH0d"]/c-wiz/div/div/div[8]/div[3]/div/div/div[2]/div/div[1]/div[1]/div[1]/div/div[4]/div[2]/div/div').click()    driver.implicitly_wait(3000)  def joinNow():    # Join meet    print(1)    time.sleep(5)    driver.implicitly_wait(2000)    driver.find_element_by_css_selector(        'div.uArJ5e.UQuaGc.Y5sE8d.uyXBBb.xKiqt').click()    print(1)  def AskToJoin():    # Ask to Join meet    time.sleep(5)    driver.implicitly_wait(2000)    driver.find_element_by_css_selector(        'div.uArJ5e.UQuaGc.Y5sE8d.uyXBBb.xKiqt').click()    # Ask to join and join now buttons have same xpaths  # assign email id and passwordmail_address = 'emaild@gmail.com'password = 'geeksforgeeks' # create chrome instanceopt = Options()opt.add_argument('--disable-blink-features=AutomationControlled')opt.add_argument('--start-maximized')opt.add_experimental_option("prefs", {    "profile.default_content_setting_values.media_stream_mic": 1,    "profile.default_content_setting_values.media_stream_camera": 1,    "profile.default_content_setting_values.geolocation": 0,    "profile.default_content_setting_values.notifications": 1})driver = webdriver.Chrome(options=opt) # login to Google accountGlogin(mail_address, password) # go to google meetdriver.get('https://meet.google.com/xby-zehb-ncf')turnOffMicCam()# AskToJoin()joinNow()
Output:
simranarora5sos
Python-selenium
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
How to Install PIP on Windows ?
Check if element exists in list in Python
How To Convert Python Dictionary To JSON?
Python Classes and Objects
How to drop one or multiple columns in Pandas Dataframe
Defaultdict in Python
Python | Get unique values from a list
Python | os.path.join() method
Create a directory in Python
Python | Pandas dataframe.groupby()