mail = driver.find_element_by_name('identifier')
mail.clear()
mail.send_keys('example@gmail.com')
mail_next = driver.find_element_by_id('identifierNext')
mail_next.click()
time.sleep(2)
password = driver.find_element_by_name('password')
password.clear()
password.send_keys('102938')
password_next = driver.find_element_by_id('passwordNext')
password_next.click()
time.sleep(2)
compose = driver.find_element_by_class_name('T-I J-J5-Ji T-I-KE L3')
compose.click()
time.sleep(2)
to = driver.find_element_by_name('to')
to.clear()
to.send_keys('example@gmail.com')
subject = driver.find_element_by_name('subjectbox')
subject.clear()
subject.send_keys('Subject')
body = driver.find_element_by_id('Am Al editable LW-avf tS-tW')
body.clear()
body.send_keys('bro, it works')
错误为"消息:无法定位元件:.T-I J-J5-Ji T-I-KE L3">
我甚至尝试了Xpath,所以很明显该类不存在于驱动程序中
我在这里找不到我做错了什么
尝试以下操作以单击GMAIL 中的撰写按钮
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//div[contains(text(),'Compose')]"))
)
except:
driver.quit()
compose = driver.find_element_by_xpath("//div[contains(text(),'Compose')]")
compose.click()
如果你想通过类来完成,下面的代码也可以。
try:
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "//div[@class = 'T-I J-J5-Ji T-I-KE L3']"))
)
except:
driver.quit()
compose = driver.find_element_by_xpath("//div[@class = 'T-I J-J5-Ji T-I-KE L3']")
compose.click()