Autosuggest text boxes are different than normal text field.
For example make my trip travel from text box,If you will type "Bhu" in text box instead of "Bhubaneswar" then in auto suggestion Bhubaneswar will display.
Steps:
1. Create WebDriver instance and Navigate to URL.
2. Find the text box and enter short text like "Bhu".
3. Store all the list elements displaying in auto suggestion.
4. Then store all the size of the list and loop until it's not matching with expected value.
5. Once it's matched with expected value click the auto suggest option.
Sample Example:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace _123342projdemo
{
public class Program
{
void execute()
{
IWebDriver driver = new ChromeDriver();
Thread.Sleep(5000);
driver.Navigate().GoToUrl("some url");
driver.FindElement(By.Id("retailer")).SendKeys("e") ;
Thread.Sleep(5000);
IList<IWebElement> listOfElements = driver.FindElements(By.XPath("//ul[@id='ui-id-1']/li"));
string text = "Retailer1, 1052";
int SizeofElements = listOfElements.Count;
for (int i = 0; i < SizeofElements; i++)
{
String option = listOfElements.ElementAt(i).Text;
Console.WriteLine(option);
if (option.Equals(text))
{
listOfElements.ElementAt(i).Click();
}
}
}
public static void Main(string[] args)
{
Program pg = new Program();
pg.execute();
}
}
}
For example make my trip travel from text box,If you will type "Bhu" in text box instead of "Bhubaneswar" then in auto suggestion Bhubaneswar will display.
Steps:
1. Create WebDriver instance and Navigate to URL.
2. Find the text box and enter short text like "Bhu".
3. Store all the list elements displaying in auto suggestion.
4. Then store all the size of the list and loop until it's not matching with expected value.
5. Once it's matched with expected value click the auto suggest option.
Sample Example:
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace _123342projdemo
{
public class Program
{
void execute()
{
IWebDriver driver = new ChromeDriver();
Thread.Sleep(5000);
driver.Navigate().GoToUrl("some url");
driver.FindElement(By.Id("retailer")).SendKeys("e") ;
Thread.Sleep(5000);
IList<IWebElement> listOfElements = driver.FindElements(By.XPath("//ul[@id='ui-id-1']/li"));
string text = "Retailer1, 1052";
int SizeofElements = listOfElements.Count;
for (int i = 0; i < SizeofElements; i++)
{
String option = listOfElements.ElementAt(i).Text;
Console.WriteLine(option);
if (option.Equals(text))
{
listOfElements.ElementAt(i).Click();
}
}
}
public static void Main(string[] args)
{
Program pg = new Program();
pg.execute();
}
}
}