gpt4 book ai didi

java - 如何获取gmail登录表单中包含错误消息的Web元素

转载 作者:行者123 更新时间:2023-11-30 05:38:52 25 4
gpt4 key购买 nike

当我输入错误的密码时,我想获取包含错误消息的 div 元素,以便我可以测试登录是否成功,但我不断收到 org.openqa.selenium.NoSuchElementException

我在网上搜索了一些解决方案,但到目前为止没有一个有效。

我的程序的其余部分工作正常 - 我可以获取电子邮件和密码元素并发送数据。我正在使用 Selenium 和 java

WebElement msg=driver.findElement(By.id("errormsg_0_Email"));
WebElement child = driver.findElement(By.xpath("//div[contains(@class, 'GQ8Pzc') and text()='Wrong password. Try again or click Forgot password to reset it.']"));

最佳答案

考虑到 gmail 页面/gmail 登录表单会动态生成类和 ID 属性,因此我将通过 normalize-text() 和内部警报文本分析。

请参阅下面的屏幕截图和适当的 XPath 定位器:

//div[normalize-space(text()) = "Couldn't find your Google Account"]

enter image description here

所以在你的情况下,XPath 定位器就像

//*[normalize-space(text()) = "Wrong password. Try again or click Forgot password to reset it."]

关于java - 如何获取gmail登录表单中包含错误消息的Web元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56098115/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com