【问题标题】:Click a button after typing in the text fields, using the Android Chrome browser在文本字段中键入后单击一个按钮,使用 Android Chrome 浏览器
【发布时间】:2019-10-24 11:36:55
【问题描述】:

我正在尝试登录网站:https://201.247.172.70/sslvpn/Login/Login 使用最新版本的appium和chromedriver,我的代码如下:

DesiredCapabilities caps = new DesiredCapabilities ();
caps.setCapability ("deviceName", "My Phone");
caps.setCapability ("udid", "4df1b558054c9fef");
caps.setCapability ("platformName", "Android");
caps.setCapability ("platformVersion", "4.3");
caps.setCapability ("browserName", "Chrome");
caps.setCapability ("noReset", "true");

System.setProperty ("webdriver.chrome.driver", "C: \\ selenium_drivers \\ chromedriver.exe");
try {
driver = new AndroidDriver <MobileElement> (new URL ("http://127.0.0.1:4723/wd/hub"), caps);

} catch (MalformedURLException e) {
System.out.println (e.getMessage ());
}
driver.get ("https://201.247.172.70/sslvpn/Login/Login");
driver.findElement (By.id ("userName")). sendKeys ("user");
driver.findElement (By.id ("passwordDisplayed")). sendKeys ("pass");
driver.findElement (By.id ("LoginButton")). click ();

当我单击时,它会响应它不存在。但在视觉上,即使它集中在场上,也能观察到控制。还观察到使用 UI Automator Viewer。

尽管如此,我尝试使用以下替代方法:

在密码字段中输入文本后隐藏键盘

driver.hideKeyboard ();

通过JS清理聚光灯

JavascriptExecutor executor3 = (JavascriptExecutor) driver;
executor3.executeScript ("document.activeElement.blur ();");

将站点缩放更改为“强制”以查看控件。

JavascriptExecutor executor2 = (JavascriptExecutor) driver;
executor2.executeScript ("document.body.style.zoom = '50% ';");

打印代码以验证是否存在

System.out.println (driver2.getPageSource ());
Where the button is observed:
<! - Submit button ->
<tr>
<td id = "LoginButtonTD" align = "right">
<div id = "submitDiv">
<input type = "submit" id = "LoginButton" name = "Login" value = "Sign In" align = "absmiddle" class = "butt" />
</ div>
</ td>
</ tr> <! - submit button ->

下面这句话我也用过

driver.findElementByXPath("//android.widget.Button[contains(@text,'Sign In')]").click();

虽然控制存在,但它不接受它。

使用电脑浏览器没有问题,但我需要移动浏览器(Android)。

enter image description here

【问题讨论】:

  • 我怀疑这是否是元素存在但尚未显示在视觉中的情况。
  • @jadcode 您是否尝试使用文本“登录”来定位元素?也可以加个Ui Automator View的屏幕截图吗?
  • @Vinod,我用了这句话:driver.findElementByXPath("//android.widget.Button[contains(@text,'Sign In')]").click();截图photos.app.goo.gl/iKWfzjySjnRhu1xr5
  • 看起来您正在混合原生和 Web 上下文,而无需在它们之间切换。
  • @Jadcode 您使用哪个安卓版本来测试这个应用程序?

标签: java android selenium appium


【解决方案1】:

4.4.2 是非常旧的 Android 版本。如果您使用低于 6.0 的任何版本,则需要切换到 WEBVIEW 并执行操作。

如果您使用的是 6.0 或更高版本,则无需切换到 WEBVIEW,Android UiAutomator 会处理它。

【讨论】:

    猜你喜欢
    • 2013-08-16
    • 1970-01-01
    • 2013-06-05
    • 2011-10-15
    • 2014-08-15
    • 2012-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多