0
votes

So I do realize that using gmail api is the best solution, but due to the gmail account having restrictions (school) I can't actually use the api. So while I was searching for the solution I have found about selenium. I haven't actually found a tutorial about how to filter emails/click on emails that is within 24 hours (which I think I can set it up myself) and click on emails with an link attached (google.meet)

Since the subject isn't always the same nor the sender, I can't actually limit it to the subject and email, so need help with some kind of email body filter.

import webbrowser
from selenium import webdriver
import time
import email
import imaplib
import sys
import datetime
import smtplib

with open('accountdetail.txt', 'r') as file:
   for details in file:
       username,password = details.split(':')

# create a new Chrome session
driver = webdriver.Chrome('C:\driver\chromedriver.exe')
driver.implicitly_wait(30)
driver.maximize_window()

# navigate to the application home page
driver.get("https://accounts.google.com/")

#get the username textbox
login_field = driver.find_element_by_name("identifier")
login_field.clear()

#enter username
login_field.send_keys(username)
login_field.send_keys(u'\ue007') #unicode for enter key
time.sleep(4)

#get the password textbox
password_field = driver.find_element_by_name("password")
password_field.clear()

#enter password
password_field.send_keys(password)
password_field.send_keys(u'\ue007') #unicode for enter key
time.sleep(10)

#navigate to gmail
driver.get("https://mail.google.com/")

I have found this resources, but for some reason they only work with subject and doesn't actually click on email with a link. How to click on a Particular email from gmail inbox in Selenium? https://www.youtube.com/watch?v=6VJaWtz6kzs

1

1 Answers

0
votes

If you have the exact link, you can get the element using XPath and click:

url = r'YOUR URL, FROM ANY VARIABLE'
driver.find_element_by_xpath('//a[@href="'+url+'"]').click()