【发布时间】:2014-12-15 00:38:20
【问题描述】:
我正在使用目前最新的 Appium v1.3.4 (REV c8c79a85fbd6870cd6fc3d66d038a115ebe22efe) 测试 Android Hybrid 应用程序。我还从这里下载了最新的 ChromeDriver:https://groups.google.com/forum/#!topic/chromedriver-users/iBdJQHu1ipQ
被测应用程序中的登录屏幕是混合视图(WebView)。因此,我通过调用 appiumDriver.context("WEBVIEW_com.my.app.pkg") 切换到正确的上下文,如下所示,我还能够使用正确的文本数据成功定位和填充用户名和密码字段以下代码:
appiumDriver.context("WEBVIEW_com.my.app.pkg");
WebElement userNameTextField = appiumDriver.findElement(By.id("username"));
userNameTextField.click();
userNameTextField.sendKeys(new String[]{"Guest"});
WebElement passwordTextField = appiumDriver.findElement(By.id("password"));
passwordTextField.click();
passwordTextField.sendKeys(new String[]{"password"});
// The following code is not working
WebElement loginButton = appiumDriver.findElement(By.id("loginbutton"));
loginButton.click();
但是,我的问题是当我尝试单击此屏幕上的登录按钮时!这就是按钮在 HTML 中的编写方式
<div href="#" id="loginbutton" class="button">Login</div>
当我在 Web 上下文中时,我尝试了很多方法来单击按钮,但到目前为止一切都是徒劳的......这是登录屏幕的 HTML sn-p
<div id="formbody">
<div class="line">
<input placeholder="Username" type="text" id="username" class="styled_input" value="">
</div>
<div class="line">
<input placeholder="Password" type="password" id="password" class="styled_input" value="">
</div>
<div class="line_button">
<div href="#" id="loginbutton" class="button">Login</div>
</div>
</div>
在多次尝试单击 Webcontext 中的 div/link 之后,我放弃并切换到 NATIVE 上下文,并且能够使用以下代码单击按钮:
appiumDriver.context("NATIVE_APP");
appiumDriver.findElementByName("Login").click();
谁能向我解释为什么我能够与 WebView 上下文中的用户名和密码文本字段进行交互,但必须切换到 NATIVE_APP 上下文才能与按钮交互?
还请注意,在 WebView 上下文中,我可以通过 id 找到按钮 ... 标记并调用 loginButton.getText()、loginButton.isEnabled()、loginButton.isDisplayed() 和 getTagName()
谢谢
【问题讨论】:
标签: android appium hybrid-mobile-app selenium-chromedriver