无法在Gmail的图片窗口中找到元素

我正在尝试创建一个脚本,该脚本将自动使用selenium发送gmail,它可以很好地发送简单的短信。但是,我希望它也允许发送图像,但是当我单击添加图像的按钮时,我无法在窗口内找到任何元素,并且它返回错误“ no这样的元素:无法找到元素” ,当我尝试时,我确定xpath是正确的(我使用的是完整的xpath,所以我知道不是因为它是动态变化的)。

在单击图像按钮后,我尝试等待,并且尝试使用 move_to_element_with_offset 从另一个元素中单击,但似乎无济于事,它不允许我查找任何内容

这是我正在使用的代码

import selenium
import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import actionChains
from selenium.webdriver.common.keys import Keys

EMAIL = 'your email'
PASS = 'your password'
TO = 'who you are sending it to'
SUB = 'subject'
MESSAGE = 'what you want to say'

driver = webdriver.Chrome()
action_chains = actionChains(driver)
action = webdriver.common.action_chains.actionChains(driver)
driver.get('https://mail.google.com/mail/u/0/#inbox')
time.sleep(2)
#Enter username
user = driver.find_element_by_xpath('//*[@id="identifierId"]')
user.send_keys(EMAIL)
#Go to password
next1 = driver.find_element_by_xpath('//*[@id="identifierNext"]/span/span')
next1.click()
time.sleep(1)
#Enter password
password = driver.find_element_by_xpath('//*[@id="password"]/div[1]/div/div[1]/input')
password.send_keys(PASS)
next2 = driver.find_element_by_xpath('//*[@id="passwordNext"]/span/span')
next2.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/div/div/div[1]/div/div")
#Create new message
compose.click()
time.sleep(2)
#Type in who your sending this to
to = driver.find_element_by_name('to')
to.send_keys(str(TO))
#Type in subject
subject = driver.find_element_by_xpath('/html/body/div[26]/div/div/div/div[1]/div[3]/div[1]/div[1]/div/div/div/div[3]/div/div/div[4]/table/tbody/tr/td[2]/form/div[3]/div/input')
subject.send_keys(SUB)
#Type in message
box = driver.find_element_by_xpath('/html/body/div[26]/div/div/div/div[1]/div[3]/div[1]/div[1]/div/div/div/div[3]/div/div/div[4]/table/tbody/tr/td[2]/table/tbody/tr[1]/td/div/div[1]/div[2]/div[1]/div/table/tbody/tr/td[2]/div[2]/div')
box.send_keys(MESSAGE)
#Open image window
imgb = driver.find_element_by_xpath('/html/body/div[26]/div/div/div/div[1]/div[3]/div[1]/div[1]/div/div/div/div[3]/div/div/div[4]/table/tbody/tr/td[2]/table/tbody/tr[2]/td/div/div/div[4]/table/tbody/tr/td[4]/div/div[5]/div/div/div')
imgb.click()
time.sleep(2)
#Attempt to open 'Get image by URL'
web = driver.find_element_by_xpath('/html/body/div[2]/div/div[3]/div[1]')
web.click() #this is where error happens

li57268631 回答:无法在Gmail的图片窗口中找到元素

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3155852.html

大家都在问