How to perform auto complete textbox operation in Selenium


I am going to demonstrate how to do automation testing a Lift application with Selenium IDE.
In some scenario there is an auto complete textbox, where we need to put the entity name, as the auto complete textbox work where browser select the element from drp down list.

Follow the below steps:

1) Type the required auto-complete name like Laptop (use TypeAndWait command & add auto-complete id or css selector)

2) Use typeKeysAndWait command for auto-complete dropdown

3) Click on auto-complete dropdown id or css selector

Code :


def attemptAutoCompleteAtTopSearchBar(func: By => WebElement, selector: String, searchText: String, startWithCount: Int,     maxNumberOfRetries: Int = 5): Unit = {
if (startWithCount <= maxNumberOfRetries && searchText.length > 0) {
func(By.cssSelector(selector))
func(By.cssSelector(selector)).clear
func(By.cssSelector(selector)).sendKeys(searchText)
try {
func(By.cssSelector("element id or class"))
func(By.cssSelector("element id or class")).sendKeys(Keys.ARROW_UP)
func(By.cssSelector("element id or class")).click
} catch {
case e: TimeoutException => attemptAutoCompleteAtTopSearchBar(func, selector, searchText.substring(0, searchText.length - 1), startWithCount + 1, maxNumberOfRetries)
case e: ElementNotVisibleException => attemptAutoCompleteAtTopSearchBar(func, selector, searchText.substring(0, searchText.length - 1), startWithCount + 1, maxNumberOfRetries)
}
}
}

Advertisements
This entry was posted in Scala, Web. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s