gpt4 book ai didi

selenium - 如何使用 Selenium2Library 查找电子邮件字段的值

转载 作者:行者123 更新时间:2023-12-03 06:33:31 24 4
gpt4 key购买 nike

我正在使用机器人框架和 Selenium2Library 库为 Web 应用程序编写回归测试。我有一个简单的测试,它更改“帐户设置”类型表单的所有字段(例如用户名、密码、电子邮件等),然后重新访问该页面并确保保存所有数据。就像这样:

*** Test Cases ***
Sample Test
Change All Account Details
New Account Details Should Be Saved

*** Keywords ***
Change All Account Details
Navigate to Account Page
Input Text accountSettingFrom_firstname Test
Input Text accountSettingFrom_lastname Dummy
Input Text accountSettingFrom_email <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d6b8b3a189b3bbb7bfba96b3aeb7bba6bab3f8b5b9bb" rel="noreferrer noopener nofollow">[email protected]</a>
# etc etc, eventually save the form

New Account Details Should Be Saved
Go To ${ACCOUNT_URL}
Textfield Value Should Be accountSettingFrom_firstname Test
Textfield Value Should Be accountSettingFrom_lastname Dummy
Textfield Value Should Be accountSettingFrom_email <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="305e55476f555d51595c705548515d405c551e535f5d" rel="noreferrer noopener nofollow">[email protected]</a>

运行此测试时,我在最后一步 ( Textfield Value Should Be accountSettingFrom_email <a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="fc92998ba399919d9590bc99849d918c9099d29f9391" rel="noreferrer noopener nofollow">[email protected]</a> ) 中收到以下错误: Value of text field 'accountSettingFrom_email' should have been '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1c72796b4379717d75705c79647d716c7079327f7371" rel="noreferrer noopener nofollow">[email protected]</a>' but was 'None'

我在该步骤运行之前截取了屏幕截图,并添加了暂停并手动确认 value “accountSettingFrom_email”的属性确实是“new_e [email protected]” '。检查发生时元素的 HTML:

<input type="email" name="accountSettingFrom[email]" value="<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="345a51436b5159555d5874514c55594458511a575b59" rel="noreferrer noopener nofollow">[email protected]</a>" class="foo bar" required="required" tabindex="3" maxlength="128" url="/foo/bar" userid="foobar" id="accountSettingFrom_email">

您会注意到前两个 Textfield Value Should Be关键词通过。我可以辨别这三个元素之间的唯一区别是“accountSettingFrom_email”是 type="email"而不是type="text" ,但是如果the关键字成功定位到元素,那为什么不能获取value的值呢?属性?

所以我做错了什么吗?我觉得必须存在这个或一些类似的关键字来测试它,而不必求助于编写自定义库。

最佳答案

您在 Selenium2Library 中遇到了一些错误。当 Selenium2Library 创建时,HTML5 尚未获得批准。在内部,库会过滤掉您的元素,因为它的类型不是“文本”(在 HTML5 之前有意义)。 Textfield Value Should Be 仅当元素具有标签名称输入和类型属性值“text”时才能找到该元素。请参阅https://github.com/robotframework/Selenium2Library/issues/546

此外,由于 Textfield Value Should Be 的实现方式,您收到的错误会让您认为该元素已找到,而实际上并未找到,因为它已被过滤掉。请参阅https://github.com/robotframework/Selenium2Library/issues/547

相比之下,输入文本输入密码从未根据元素标签或属性进行过滤。

关于selenium - 如何使用 Selenium2Library 查找电子邮件字段的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34169390/

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