I have just started using selenium with Python for the first time, after following a quick tutorial I am now trying to make a program with it that will login to Gmail and then send an email to a chosen email address.
I've gotten the login part done but had some problems with the composing a new email part (only works some of the time) and I get stuck everytime when it comes to writing the message body.
My code is below, I have tried reading the docs but Im having trouble getting the following to work in Gmail and the when I inspect the elements in gmail it seems a lot more complex than the basic html structures in the examples here:
Write a program that takes an email address and string of text on the command line and then, using Selenium,
logs into your email account and sends an email of the string to the provided address.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome()
emailElem = browser.find_element_by_id('Email')
passwordElem = browser.find_element_by_id('Passwd')
composeElem = browser.find_element_by_class_name('z0') #this only works half of the time
toElem = browser.find_element_by_name("to")
subjElem = browser.find_element_by_name("subjectbox")
subjElem.send_keys('Test with selenium')
bodyElem = browser.find_element_by_???('???') #this is where I get stuck and not sure what to do here
bodyElem.send_keys('A test email with selenium')
sendElem = browser.find_element_by_link_text('send') #not sure if this is correct too
I think the easiest way to select elements on a loaded page is to find them by css selector. You can find them in the browser inspector, and then copy their unique css selector (in firefox press inspect element -> copy unique selector). In this case this should work: