2016-08-12 67 views
0

应用包括动态搜索框& 而输入“孟买”的搜索结果如下下拉显示, 但通过硒作为,动态搜索无法通过硒webdriver显示结果?

driver.findElement(By.id("searchstr2")).sendKeys("Mumbai"); 

driver.findElement(By.id("searchstr2")).sendKeys("Mumbai"+ARROW_DOWN); 

搜索结果不显示为, enter image description here

文本框ht ml为,

<input id="searchstr2" class="search ui-autocomplete-input" type="text" placeholder="Search for Building, Location or Developer" autocomplete="off" name="searchstr2" size="35" style="background-image: none;" 

成功的搜索列表中显示为后,

<li id="ui-id-117" class="ui-menu-item" tabindex="-1"> 
 
<a> 
 
Nariman Point - 
 
<b style="font-size:11px"> 
 
<span style="font-size:.8em; /*color:#EE7600;*/ color:#888888; float:right;">locality</span> 
 
</a> 
 
</li> 
 
<li id="ui-id-118" class="ui-menu-item" tabindex="-1"> 
 
<li id="ui-id-119" class="ui-menu-item" tabindex="-1"> 
 
<li id="ui-id-120" class="ui-menu-item" tabindex="-1"> 
 
<li id="ui-id-121" class="ui-menu-item" tabindex="-1">

请建议。

+0

你能分享你的网站的网址? –

+0

实际上这个功能在应用程序的后端,因此它需要凭证登录。我可以分享相同的HTML管理单元吗? – Chetan

+0

实际上没有看到活的场景,很难说什么是问题... –

回答

0

Java脚本,需要一些时间来加载列表,所以我必须在增加计时器发送姓名之间&向下箭头键事件将是对我的作品的代码卡作为,

WebElement ar=driver.findElement(By.id("searchstr2")); 
ar.sendKeys("Mumbai"); 
Thread.sleep(2000); 
ar.sendKeys(Keys.ARROW_DOWN); 
1

自动填充字段的问题在于,通常会有一个Javascript事件等待文本出现在字段中以显示可用的建议(可能是执行的Ajax以从服务器获取建议) 。 SendKeys不会触发该事件,因此您可以在输入文字后尝试点击该字段。 基本上是:

WebElement suggestion = driver.findElement(By.id("searchstr2")); 
suggestion.sendKeys("Mumbai"); 
suggestion.click(); 

我没有测试这一点,所以你可以尝试使用click()方法sendKeys()之前。

如果不能解决您的问题,您可以尝试使用JavaScript来触发onChange事件做到这一点:

WebElement suggestion = driver.findElement(By.id("searchstr2")); 
suggestion.click(); 
suggestion.sendKeys("Mumbai"); 
((JavascriptExecutor) driver).executeScript("$(arguments[0]).change(); return true;", suggestion); 
+0

感谢您的帮助,但上面的解决方案不工作(即列表不显示),而按下按键而不是点击,列表将显示,但“Keys.ARROW_DOWN”也不起作用。你能根据这个建议吗? – Chetan

+0

只需等待我的工作,感谢您的帮助。 – Chetan