[英]How can I send an email from Gmail with Python + Selenium?
I'm trying to send an email from Gmail's web interface with Python using Selenium, but I'm stuck on the part of selecting the Compose part.
这是我的代码:
from selenium import webdriver
import time
driver = webdriver.Chrome('C:\chromedriver.exe')
driver.get('https://www.gmail.com/')
driver.implicitly_wait(5)
loginBox = driver.find_element_by_xpath('//*[@id ="identifierId"]')
loginBox.send_keys('xxxxxxxxxxxxxxxxx')
nextButton = driver.find_elements_by_xpath('//*[@id ="identifierNext"]')
nextButton[0].click()
passWordBox = driver.find_element_by_xpath('//*[@id ="password"]/div[1]/div / div[1]/input')
passWordBox.send_keys('xxxxxxxxxxxx')
nextButton = driver.find_elements_by_xpath('//*[@id ="passwordNext"]')
nextButton[0].click()
time.sleep(2)
#compose = driver.find_element_by_xpath('/html/body/div[7]/div[3]/div/div[2]/div[1]/div[1]/div[1]/div[2]/div/div/div/div[1]/div/div')
#compose.click()
driver.get('https://mail.google.com/mail/u/0/#inbox?compose=new')
time.sleep(2)
compose_button_xpath="/html/body/div[7]/div[3]/div/div[2]/div[1]/div[1]/div[1]/div[2]/div/div/div/div[1]/div/div"
#driver.find_element_by_xpath(compose_button_xpath).click()
driver.find_element_by_xpath("//textarea[@name='to']").send_keys("abc@gmail.com")
driver.find_element_by_xpath("//*[@id=':12s']").send_keys("Content")
driver.find_element_by_xpath("//*[@id=':11d']").click()
你能帮助我吗? 我该如何解决这个问题?
哇,Gmail 的 HTML 真是一团糟。
无论如何,我已经用这个 xPath 找到了撰写按钮:
'//*[contains(@class, "T-I") and contains(@class, "L3") and contains(@class, "T-I-KE")]'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.