title: How to close a browser tab with Selenium at a given time
body: <p>I have been working on this script that automatically joins google meets. It logs in to gmail and then goes to the meeting automatically if it is the time for meeting. But, now I am having problems with leaving the meeting after certain time. I want to just close a browser tab, thus the meeting. Then continue checking for the next meeting. I think the last while loop that is intended to close the chome tab after the meeting is done does not run at all. I have tried replacing it with print statements to see if it is executed, but it does not. I do not know why not tho.</p>
  <pre><code>from selenium import webdriver
  from selenium.webdriver.common.keys import Keys
  from selenium.webdriver.chrome.options import Options
  import datetime
  import time
  import signal
  
  now = datetime.datetime.now()
  current_time = now.strftime(&quot;%H:%M / %A&quot;)
  
  justtime = now.strftime(&quot;%H:%M&quot;)
  print (current_time)
  
  
  def Glogin(mail_address, password):
      #os.system(&quot;obs --startvirtualcam &amp;&quot;)
      # Login Page 
      driver.get( 
          'https://accounts.google.com/ServiceLogin?hl=en&amp;passive=true&amp;continue=https://www.google.com/&amp;ec=GAZAAQ') 
  
      # input Gmail 
      driver.find_element_by_id(&quot;identifierId&quot;).send_keys(mail_address) 
      driver.find_element_by_id(&quot;identifierNext&quot;).click() 
      driver.implicitly_wait(10) 
  
      # input Password 
      driver.find_element_by_xpath( 
          '//*[@id=&quot;password&quot;]/div[1]/div/div[1]/input').send_keys(password) 
      driver.implicitly_wait(10) 
      driver.find_element_by_id(&quot;passwordNext&quot;).click() 
      driver.implicitly_wait(10) 
  
      # go to google home page 
      driver.get('https://google.com/') 
      driver.implicitly_wait(100)
      driver.get(sub)
      # turn off Microphone 
      time.sleep(1)
      #driver.find_elements_by_class_name(&quot;JRY2Pb&quot;)[0].click()
      driver.find_elements_by_class_name(&quot;JRY2Pb&quot;)[0].click()
      # switch camera
      time.sleep(2)
      for x in driver.find_elements_by_class_name(&quot;JRtysb&quot;):
          x.click()
      time.sleep(2)
      for a in driver.find_elements_by_class_name(&quot;FwR7Pc&quot;):
          a.click()
      time.sleep(2)
      for b in driver.find_elements_by_class_name(&quot;XhPA0b&quot;):
          b.click()
      time.sleep(2)
      driver.find_element_by_tag_name('body').send_keys(Keys.TAB + Keys.TAB + Keys.ARROW_DOWN + Keys.ENTER)
      time.sleep(1)
      webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform()
      time.sleep(2)
      # Join meet 
      time.sleep(1) 
      driver.implicitly_wait(2000) 
      driver.find_element_by_css_selector( 
          'div.uArJ5e.UQuaGc.Y5sE8d.uyXBBb.xKiqt').click()
      
  # assign email id and password
  mail_address = 'email'
  password = 'password'
  
  # create chrome instamce 
  opt = Options() 
  opt.add_argument('--disable-blink-features=AutomationControlled') 
  opt.add_argument('--start-maximized')
  opt.add_experimental_option(&quot;prefs&quot;, { 
      &quot;profile.default_content_setting_values.media_stream_mic&quot;: 1, 
      &quot;profile.default_content_setting_values.media_stream_camera&quot;: 1, 
      &quot;profile.default_content_setting_values.geolocation&quot;: 0, 
      &quot;profile.default_content_setting_values.notifications&quot;: 1
  })
  
  while True:
  
      if current_time == &quot;05:00 / Wednesday&quot;:
          
          sub = &quot;link&quot;
          driver = webdriver.Chrome(options=opt, executable_path=r'/usr/bin/chromedriver') 
          Glogin(mail_address, password)
          break
      
  while True:
      if current_time == &quot;05:01 / Wednesday&quot;:
          driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + 'w')
          break
              
  
          
  
          
  </code></pre>