等待收到Gmail电子邮件

2024-09-30 06:32:38 发布

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

目前有一个gmail帐户,收件箱中没有电子邮件。我想能够显示一个弹出窗口与当前的电子邮件数量。如果没有电子邮件,则不显示任何消息。在

所以我选择使用显式Waits&Xpath来实现这一点。据我所知,这允许我定义一个时间段(比如10秒),然后每500毫秒,代码将查询并检查元素是否包含正确的文本,如下面函数的第二个参数所指定的那样。在

wait = WebDriverWait(driver, 10)

wait.until(EC.element_to_be_present_in_element((By.XPATH, "//*[@id=':3s']/div/div[1]/span/a/"), 'Inbox (1)'))

xpath位置是“收件箱”按钮的xpath。它有一个可以改变的值。(如果愿意,可以在自己的浏览器中进行验证)

实际上,我只是第一次运行它(第一次运行它,在我发布之后,不要问为什么),并得到以下错误代码:

^{pr2}$

AttributeError:“module”对象没有属性“element”to“u be”present“in”element

实施后:

wait.until(EC.presence_of_element_located((By.XPATH, "//*[@id=':3s']/div/div[1]/span/a[text()[contains(.,'Inbox (1)')]]")))

我在编译时仍然遇到这个错误:

Traceback (most recent call last):
  File "C:/Users/singhgurp/Desktop/Report/Web_2.py", line 51, in <module>
wait.until(EC.presence_of_element_located((By.XPATH, "//*[@id=':3s']/div/div[1]/span/a[text()[contains(.,'Inbox (1)')]]")))
  File "C:\Python34\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message: 
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///C:/Users/SINGHG~1/AppData/Local/Temp/tmpq64vsuyi/extensions/fxdriver@googlecode.com/components/driver-component.js:10770)
at FirefoxDriver.prototype.findElement (file:///C:/Users/SINGHG~1/AppData/Local/Temp/tmpq64vsuyi/extensions/fxdriver@googlecode.com/components/driver-component.js:10779)
at DelayedCommand.prototype.executeInternal_/h (file:///C:/Users/SINGHG~1/AppData/Local/Temp/tmpq64vsuyi/extensions/fxdriver@googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///C:/Users/SINGHG~1/AppData/Local/Temp/tmpq64vsuyi/extensions/fxdriver@googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///C:/Users/SINGHG~1/AppData/Local/Temp/tmpq64vsuyi/extensions/fxdriver@googlecode.com/components/command-processor.js:12608)

这个页面有1封电子邮件,所以它应该可以工作,不知道为什么它不能。在


Tags: divlocalextensionselementusersappdatatempat
1条回答
网友
1楼 · 发布于 2024-09-30 06:32:38

您应该使用:

wait.until(EC.presence_of_element_located((By.XPATH, "//*[@id=':3s']/div/div[1]/span/a"))

在selenium python doc中,没有方法element_to_be_present_in_element来检查页面中是否有预期的元素,但是doc引用方法presence_of_element_located

文件:http://selenium-python.readthedocs.io/waits.html

相关问题 更多 >

    热门问题