Interview Question Identify the Duplicate Items in the Listbox|HashMap|Selenium WebDriver



In Selenium WebDriver selecting a values from the Listbox is important based on the required input. In few scenario’s we need to validate the Listbox contains duplicate items are getting displayed as per the requirements. And also in interviews the mostly asked question is how to identify the duplicate values in the Listbox.
In order to automate this scenario, i have created a HTML webpage using the following html source code. Create a new File and copy the below contents of the html source into notepad and save the script in a file named ListboxEx.html. Access the HTML file and open in an browser to view the contents of the html page.

HTML SOURCE CODE

SELENIUM WEBDRIVER LOGIC:

CONCLUSION:
Using HashMap we can identify the duplicate option values in the Listbox
OUTPUT:
The size of the list is :: 5
Duplicate value in the List SELENIUM
The size of the hMAP :: 4
FAILED: validateDuplicateItemsInList
validate the list does not contain any duplicates
java.lang.AssertionError: expected [4] but found [5]

Leave a Reply

Your email address will not be published. Required fields are marked *