【问题标题】:Android WebDriver unable to enter text in the 2nd Text Box( subsequent elements)Android WebDriver无法在第二个文本框中输入文本(后续元素)
【发布时间】:2013-01-16 16:52:18
【问题描述】:

描述/步骤:

如果使用以下代码调用屏幕(附加 HTML 文件),则使用最新的 android webdriver (selenium-java-2.28.0.zip):

#######################################3
WebDriver driver = new AndroidDriver();
driver.get("http://10.178.147.244:8080/TestConnected");
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.findElement(By.id("test")).sendKeys("Test");

Thread.sleep(10000);

WebElement ele=driver.findElement(By.id("username"));
ele.sendKeys("Test");
#

文本在屏幕的第一个字段中输入,但焦点从未移动到下一个文本框。

在任何运行中,代码只作用于屏幕上的任何一个元素。

甚至尝试使用以下方法:

driver.findElement(By.name("test")).sendKeys(Keys.RETURN);

driver.findElement(By.name("test")).sendKeys(Keys.TAB);

预期的输出是什么?你看到了什么?

脚本应该在屏幕上所有可用的文本框中输入值。

Selenium 版本:selenium-java-2.28.0 操作系统:安卓2.3 浏览器:安卓浏览器 浏览器版本:HTC Desire Android Browser

网页代码:

<html>
<head>

<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

 <link rel="stylesheet" type="text/css" href="css/mobileAppUI.css"/>




</head>
<body >

 <br/>
 <div id="wholeBody">


   <table align='center' >

    <tr id='mdttagtr'>

        <td width='30%' class="oraLabel"><script type="text/javascript">document.write(LABELS.mdttag)</script></td>
        <td width='70%'>
        <input name='test' class="oraInput" type="text" id="mdttag" />

        </td>

    </tr>
    <tr>
        <td width='30%' class="oraLabel" id='userLabel'><script type="text/javascript">document.write(LABELS.userId)</script></td>

        <td width='70%'>
        <input name='username' class="oraInput" type="text" id="username" maxlength="256"/>

        </td>
    </tr>


</table>

 <hr/> 

【问题讨论】:

  • 目前我可以使用 Webdriver 中的 JavaScript 执行器来完成此操作。如果有更好的方法,请告诉我。

标签: android selenium webdriver


【解决方案1】:

尝试按名称查找元素,然后使用 sendKeys 方法。它对我有用。

【讨论】:

  • safari 驱动也出现了同样的问题,并确认这是 safari 驱动的 webdriver 错误。我认为 Android 驱动也受此错误影响。我尝试使用 XPath,但没有t 工作。但按名称,它工作。你可以像这样做工作。Thnks
【解决方案2】:

您为第一个输入元素输入了错误的 ID。

driver.findElement(By.id("test")).sendKeys("Test");

//here id mention in your html is "mdttag"
<input name='test' class="oraInput" type="text" id="mdttag" />

【讨论】:

    【解决方案3】:

    要在第二个文本字段中输入文本,请使用“按名称”选择器

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-02-08
      • 2014-12-13
      • 2016-12-11
      • 1970-01-01
      • 2016-12-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多