1

我有一个文本字段,并且 jquery 自动完成器绑定到它。

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()); 
};

我尝试过以下方式

@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");       
}
4

0 回答 0