【发布时间】:2019-08-29 21:31:54
【问题描述】:
我需要在 iOS 模拟器上测试这个登录表单,但是当我尝试在元素 '//input[@name="email"]' 上插入文本时,文本被放置但是当我选择元素 '//input[@name="password"]' 时,第一个元素中的文本消失了,同样的情况发生当我按下'//div[@id="react-component-login-header']//button/div/span[1]" 元素时。
我认为问题与文本的输入方式有关,因为使用 Selenium2Library(用于桌面)没有这个问题。
还有其他方法可以在字段上插入文本吗?我在使用其他库或在 Python 上创建关键字来辅助测试时没有任何问题(已经在其他测试中这样做了)。
我已经尝试过:
输入文本
输入值
输入密码(我知道,但我需要尝试其他方法)
*** Settings ***
Library Dialogs
Library AppiumLibrary
*** Variables ***
${defaultTimeout} 15s
*** Test Cases ***
TC001
[Setup] Configuration
Start Test
Wait Until Page Contains Element //*[@id='age-gate-yes'] ${defaultTimeout}
Click Element //a[@id='age-gate-yes']
Wait Until Page Contains Element //a[@href="/profile"] ${defaultTimeout}
Click Element //a[@href="/profile"]
Wait Until Page Contains Element //input[@name="email"] ${defaultTimeout}
Click Element //input[@name="email"]
Input Text //input[@name="email"] johndoe@john.doe
Click Element //input[@name="password"]
Input Text //input[@name="password"] JohnDoe123
Click Element //div[@id='react-component-login-header']//button/div/span[1]
Wait Until Page Does Not Contain Element //div[@id='react-component-login-header']//button/div/span[1] ${defaultTimeout}
[Teardown] End Test
我可以看到正在写在字段上的文本,但是当该元素的上下文丢失时,文本也会丢失。
【问题讨论】:
-
我不明白您是如何尝试输入文本的。你可以试试 sendKey() 方法。
driver.findElementById("element id").sendKey("your text") -
我尝试使用来自 AppiumLibrary 的关键字输入文本:AppiumLibrary.Input Text //input[@name="email"] johndoe@john.doe
-
你试过 sendKey() 方法了吗?
-
很抱歉,该方法在哪个库中?我已经尝试了 Library SendKeys 但没有成功,它在我的桌面上输入,而不是在虚拟机或模拟器上。
-
定义在org.openqa.selenium.remote
标签: appium robotframework