Not able to select options from dropdown

I am not able to run a test where I am trying to select a particular option from dropdown in a web application. The dropdown is created using a third party library and not with ‘Select’ tags. The xpath of the element that I want to select looks like:

Team Role

and the script looks like:

WebUI.click(findTestObject(‘Object Repository/Page_Procedure Template Test_Ank_Installation_Template Task List/td_Team Role’))

where ‘td_Team_Role’ is the TestObject. PFB screenshot:

I get error like ‘element not interactable’ if I choose the selection method as xpath. If I choose attributes, the error says that element not found.

I have not done any changes in the recorded test case.

Is there any workaround?

If you have an id ( you do) and it’s not dynamic (i.e. it doesn’t change each time the page is loaded) then you can trim away everything else and just use that.

Try it. Uncheck everything, leave xpath checked.

If that doesn’t work, post the HTML (screen shot is fine) surrounding the dropdown.

Thanks Russ_Thomas.

I have an ID and it is dynamic. If you see the number ‘7’ it changes depending upon the number on elements in the dropdown. However even with fixed no. of elements it does not work by unchecking everything and keeping just xpath. It gives error of ‘element not interactable’. PFB the screenshot of html:

Right. So…

  1. Because it’s dynamic, the id is essentially useless from a testing perspective.
  2. The error is common. Your test runs like lightning. The browser by comparison runs like a pregnant elephant. Slow the test down.
1 Like

I will also add that the dynamic id is not an impossible problem. You can almost always come up with a custom xpath that will identify your element every time.

This is especially true in your case; <td> elements are table elements, which means you can usually find the one you want using indices in your xpath. If you can find the ancestor <table> element, I can probably give you a good xpath that avoids the dynamic id attribute value.

1 Like

I have tried this. But this doesn’t help. Still the same issue.

I am wondering why the recorded steps not working? I believed they should work without any issues.

I am not sure how to find the ancestor table in Katalon. In the HTML image attached, you can see the ancestor table. Can you please help in getting the xpath?

Sorry, I was looking at the first element highlighted in your screenshot, not the bottom one. Try this:

//table[@id=‘treeHL_tEF__dxddlJobRole_DDD_L_LBT’]//tr[8]/td

This would identify the 8th row of that table. You could also find it by text, which might work better if the position of the target dropdown changes:

//td[text()=‘Team Role’]

I would recommend testing custom xpaths in your browser console first, before going through the trouble of creating a Test Object. Press F12 on your browser to open the inspector, go to the Console tab and enter your xpath like this:

$x(“//myxpath”)

1 Like

Thanks Brandon_Hein for adding to my knowledge about searching xpath.

However this didn’t solve my problem. Gives the same error of element not interactable.
I tried another solution as given by you in another thread:

PFB code:

WebDriver driver = DriverFactory.getWebDriver();
WebElement table = driver.findElement(By.xpath(“//*[@id=‘treeHL_tEF__dxddlJobRole_DDD_L_LBT’]/tbody”));

List rows = table.findElements(By.tagName(‘tr’))

int rows_count = rows.size()

Loop:
for (int row = 0; row < rows_count; row++)
{
List Columns_row = rows.get(row).findElements(By.tagName(‘td’))
String celltext = Columns_row[0].getAttribute(“id”)

if (celltext.equalsIgnoreCase("treeHL_tEF__dxddlJobRole_DDD_L_LBI7T0")) 
{
	Columns_row[0].selected = 	true;
}

break Loop;

}

I then debugged the code and found the celltext getting the correct IDs. However for every value it goes inside the IF loop. So couldn’t check further.

Your core problem is of course the ‘not interactable’ bit, but you should still make sure your xpath is returning the correct element before investigating its interactability.

Can you test it in your browser console and share a screenshot of what you get back?

Hi Ankush,

Is it possible to share website link?

The XPATH is returning correct element. I have verified it in browser as well as while debugging. What I observed now, while debugging, if I click on the dropdown manually then the execution works fine and can select the desired option.

So I added following code:

WebElement jobRoledropdown = driver.findElement(By.xpath("//input[@id=‘treeHL_tEF__dxddlJobRole_I’]"));

jobRoledropdown.sendKeys("");
driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS) ;

jobRoledropdown.click();

This works perfectly fine while debugging (without manually clicking on dropdown).

However if I try to execute it in run mode it doesn’t work. It doesn’t give any error, however, the option is not selected.

I tried adding delay as you can see. I also tried JavascriptExecutor, however it also didn’t work for me.

Can you help me in solving this riddle now?

Is this delay actually working? I’ve never implemented a wait like that… Try either of these instead:

Thread.sleep(10000)

or

WebUI.delay(10)

Finally it solved the problem.

The delay was not working somehow. Apparently even the WaitforElementVisible doesn’t seem to work.

I am not sure whether adding delay this way is a good practice or not, however it solved the problem. Also all the above code was not necessary, simple click worked.

Adding a hard wait is generally not good practice, but it can be useful for determining whether you have a timing issue or not, like in this case. You should take the time to implement a proper wait condition at some point, but at least you know what the issue is :slightly_smiling_face: Cheers!

1 Like