Selenium无法找到“撰写电子邮件”按钮的元素

2024-06-02 06:57:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在使用Python发送Gmail,进展良好。不幸的是,Selenium在识别允许用户编写和发送电子邮件给用户的“撰写”按钮时遇到了问题

from selenium import webdriver
your_email = input("Email:")
your_password = input("Password:")
if "@cps.edu" in your_email:
    your_email_two = your_email.replace("@cps.edu","")
driver = webdriver.Chrome("C:/Users/Shitty Horrible Pc/PycharmProjects/learningpython/pytjom/chromedriver.exe")
driver.implicitly_wait(4)
driver.get("https://gmail.com")
element = driver.find_element_by_id("identifierId")
element.send_keys(your_email)
element = driver.find_element_by_class_name("VfPpkd-RLmnJb")
element.click()
element = driver.find_element_by_id("identification")
element.send_keys(your_email_two)
element = driver.find_element_by_id("ember489")
element.send_keys(your_password)
element = driver.find_element_by_id("authn-go-button")
element.click()
element = driver.find_element_by_class_name("VfPpkd-RLmnJb")
element.click()
driver.maximize_window()
driver.implicitly_wait(20)
element = driver.find_element_by_class_name("T-I T-I-KE L3")
element.click()
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".T-I T-I-KE L3"}

我尝试最大化选项卡,告诉Selenium在尝试定位元素之前等待,但都没有用。我也研究过类似问题上面的其他帖子,但没有多大帮助。我应该尝试删除类名中的空格吗?还有什么我能做的吗

Picture of Gmail with compose button and the element type + name


Tags: 用户namesendidyourbyemaildriver
1条回答
网友
1楼 · 发布于 2024-06-02 06:57:17

我想我通过使用较旧的HTML版本的Gmail解决了我的问题https://mail.google.com/mail/u/0/h/s32qz81kdosc/?zy=h&;f=1”)

识别“撰写电子邮件”元素并按下它的代码:

element = driver.find_element_by_link_text("Compose Mail")
element.click()

如果需要,可以添加隐式或显式等待

相关问题 更多 >