How to add selenium test coverage for jquery autocompleter text field

落爺英雄遲暮 提交于 2020-02-23 05:35:33

问题


I have a text field , and jquery auto completer is binded to it.

html

<div id="autoCompleter">
   <input type="text" name="symbol" />
</div>

javascript

 $('#autoCompleter').delegate("input", "focus", AutoCompleter); 
   var AutoCompleter = function(event) {    
    $(this).autocomplete({
        source: function(request, response) {
            jQuery.extAjax({
                url: url,
                data: data,
                success: response
            });
        },
        select: function(event, ui) {
            if (ui.item.value.match(/^Enter more characters...$/)) {
                return false;
            }
        },          
        focus: function(event, ui) {
            if (ui.item.value.match(/^Enter more characters...$/)) {
                return false;
            }
        },
        minLength: 2
    }); 
    $(this).autocomplete("search", $(this).val()); 
};

I have tried in the following way

@Test
public void autoCompleter() {       
    driver.findElementByName("symbol").sendKeys("22");      
    common.patientlyFindElement(By.xpath("//ul[contains(@class, 'ui-autocomplete')]//a[contains(.,'Enter more characters...')]")).click();      
    assertEquals(driver.findElementByName("symbol").getAttribute("value"), "22");       
}

来源:https://stackoverflow.com/questions/13175246/how-to-add-selenium-test-coverage-for-jquery-autocompleter-text-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!