2016-08-12 69 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