我希望能有人幫忙。我試圖針對搜索功能編寫測試,當用戶在搜索框中輸入幾個字符時,會向您提供與您輸入的條件相匹配的建議。在我的示例中,我在搜索字段中輸入單詞'cel',然後返回3個列表項。該代碼沒有錯誤,foreach循環返回列表中的所有三個項目,但'suggestion.Click()'沒有被執行,我不知道爲什麼。爲了給出一些上下文,這是一個在線問候網站。Click() - 沒有在我的foreach循環內執行
<li ng-click="goSearch('Autocomplete', 'keyword')" ng-bind-html="searchForMsg()" class="ng-binding">Search for <strong>"cel"</strong></li>
<li ng-repeat="suggestion in (suggestions = (allFacetsAutoComplete.facets | typeahead:moonpigSearchBox.term))" ng-bind-html="highlight(suggestion.DisplayName)" ng-click="selectSuggestion(suggestion)" ng-bind="suggestion.DisplayName" class="ng-binding ng-scope"><strong>cel</strong>ebration</li>
<li ng-repeat="suggestion in (suggestions = (allFacetsAutoComplete.facets | typeahead:moonpigSearchBox.term))" ng-bind-html="highlight(suggestion.DisplayName)" ng-click="selectSuggestion(suggestion)" ng-bind="suggestion.DisplayName" class="ng-binding ng-scope">jewish <strong>cel</strong>ebrations</li>
[Then(@"I select the following list item '(.*)' from my search")]
public static void PreSelectedListOptions(string value)
{
var suggestedList = Driver.Instance.FindElements(By.CssSelector(".list-reset li"));
foreach(IWebElement suggestion in suggestedList)
{
if(value.Equals(suggestion))
{
suggestion.Click();
}
}
}
And I perform a partial search for 'cel'
And I select the following list item 'ebration' from my search
//Note: I have just copied a part of the scenario.
非常感謝
但你的代碼在if子句中跳轉嗎?所以有建議是等於你的價值? – drkthng
謝謝你的幫助:) –