Is there a method to capture this type of drop down

I want to go my account option in here(as attached screen shot). I tried with different methods mentioned in the documentation. but still i couldn’t click on “my account” option in this drop down. Is there anyway to do that.

Hi Rushantha,

There are several ways to click that dropdown item. As you can see in the html source, it has a unique locator of _ngcontent-c2 class=“dropdown-item my-account”. Use that as your test object locator…

//just do a simple click
WebUI.click(findTestObject("your_dropdown-image"))
WebUI.waitForElementVisible(findTestObject("your_dropdown-Item_MyAccount"), 30)
WebUI.click(findTestObject("your_dropdown-Item_MyAccount"))

Or

Do it in a coded way. . . since it is a drop down, click the drop down image first and then collect the items…
How to do it? Get the common locator of those two items, which is “dropdown-item” then make that as your test object then follow the simple code below:

//this will collect the dropdown items once it becomes visible in the website
java.util.List<WebElement> dropDownItems = WebUiCommonHelper.findElements(findTestObject("your_testObject"), 30)

/**
it will be stored in your list of webelement like this
0 = My Account
1 = Logout
**/

//to click that "My Account", do a click event using the list's index
dropDownItems[0].click()

That is also a convenient way if you need to logout after the test
just use the index of “Logout”, no need to create another test object…

Make sure to import WebElement.

Hope that helps. . . :slight_smile:

2 Likes

@Arnel… Thanks for the help…let me try… :grinning:

Hi @Arnel… Yes it is working … Thanks a lot… :+1::+1:

Cool!

Cheers. . . :beers: