如何使用 Selenium2Library 查找电子邮件字段的值
How to find value of email field using Selenium2Library
我正在使用机器人框架和 Selenium2Library 库为 Web 应用程序编写回归测试。我有一个简单的测试,它更改了 "account settings" 类型表单的所有字段(想想用户名、密码、电子邮件等),然后重新访问该页面并确保所有数据都已保存。像这样:
*** 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 new_email@example.com
# 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 new_email@example.com
当 运行 此测试时,我在最后一步 (Textfield Value Should Be accountSettingFrom_email new_email@example.com
) 收到以下错误:Value of text field 'accountSettingFrom_email' should have been 'new_email@example.com' but was 'None'
我在那个步骤运行前一刻截图了,我加了个暂停,手动确认'accountSettingFrom_email'的value
属性确实是'new_email@example.com'。检查发生时元素的 HTML:
<input type="email" name="accountSettingFrom[email]" value="new_email@example.com" 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"
,但是如果关键字成功定位到元素,那么为什么它不能抓取value
属性的值?
那我是不是做错了什么?我觉得必须存在这个或一些类似的关键字来测试这个,而不必诉诸编写自定义库。
我会尝试 Get Element Attribute 来获取名为 value
的属性。根据 API 应该是
accountSettingFrom_email@value
您在 Selenium2Library 中遇到了一些错误。创建 Selenium2Library 时,HTML5 未被批准。在内部,库正在过滤掉您的元素,因为它的类型不是 'text'(在 HTML5 之前有意义)。 Textfield Value Should Be
只能找到您的元素,如果它具有标签名称输入和属性值 'text' 类型。
参见 https://github.com/robotframework/Selenium2Library/issues/546
另外,由于 Textfield Value Should Be
的实现方式,您收到的错误让您认为该元素已找到,但实际上并没有找到,因为它已被过滤掉。
参见 https://github.com/robotframework/Selenium2Library/issues/547
相比之下,Input Text
和 Input Password
从未对元素标签或属性进行过滤。
我正在使用机器人框架和 Selenium2Library 库为 Web 应用程序编写回归测试。我有一个简单的测试,它更改了 "account settings" 类型表单的所有字段(想想用户名、密码、电子邮件等),然后重新访问该页面并确保所有数据都已保存。像这样:
*** 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 new_email@example.com
# 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 new_email@example.com
当 运行 此测试时,我在最后一步 (Textfield Value Should Be accountSettingFrom_email new_email@example.com
) 收到以下错误:Value of text field 'accountSettingFrom_email' should have been 'new_email@example.com' but was 'None'
我在那个步骤运行前一刻截图了,我加了个暂停,手动确认'accountSettingFrom_email'的value
属性确实是'new_email@example.com'。检查发生时元素的 HTML:
<input type="email" name="accountSettingFrom[email]" value="new_email@example.com" 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"
,但是如果关键字成功定位到元素,那么为什么它不能抓取value
属性的值?
那我是不是做错了什么?我觉得必须存在这个或一些类似的关键字来测试这个,而不必诉诸编写自定义库。
我会尝试 Get Element Attribute 来获取名为 value
的属性。根据 API 应该是
accountSettingFrom_email@value
您在 Selenium2Library 中遇到了一些错误。创建 Selenium2Library 时,HTML5 未被批准。在内部,库正在过滤掉您的元素,因为它的类型不是 'text'(在 HTML5 之前有意义)。 Textfield Value Should Be
只能找到您的元素,如果它具有标签名称输入和属性值 'text' 类型。
参见 https://github.com/robotframework/Selenium2Library/issues/546
另外,由于 Textfield Value Should Be
的实现方式,您收到的错误让您认为该元素已找到,但实际上并没有找到,因为它已被过滤掉。
参见 https://github.com/robotframework/Selenium2Library/issues/547
相比之下,Input Text
和 Input Password
从未对元素标签或属性进行过滤。