Go down
Active particpant
Active particpant
Posts : 14
Join date : 2012-03-30

Finding element by content with scLocator?

on Wed Apr 04, 2012 9:23 pm

I need to get element from dropdown list by its content, to check if it exists. It doesn't have id and no fixed location inside list. I managed to get it with Selenium IDE by using scLocator, but only when defining row nr. where it is at the moment:

I would like to get that element by it's content. Is something like this possible (this is not working, but maybe something similar would)?

This is html code of the element:
<td align="left" height="16" class="pickListCellSelected" style="padding-top: 0px; padding-bottom: 0px; width: 144px; overflow: hidden;">
  <div style="overflow:hidden;WIDTH:140px;" cellclipdiv="true" role="presentation" id="">

Thanks for any help...
Posts : 387
Join date : 2009-07-30
Location : India

Re: Finding element by content with scLocator?

on Tue Apr 10, 2012 1:50 pm

I have an idea, you can try this to perform, what you want to do.

xpath for locator on basis of html code: //td[@class'pickListCellSelected']//div[@role='presentation']

Assume the above x-path point to list, if not; modify it.

now what you can do:

1. fetch all the elements of list.
2. find the value you want to select and fetch it's position to get an index.
3. after getting index , use the command which you are using and working.

but this will require programming effort. you can add you own API which gives you a index number of list on basis of value and add it into IDE to use it. Create user extension for IDE or use RC for full fledge code.

Hope this will help. best of luck.


Spread Your Knowledge About Selenium Tool.

Active particpant
Active particpant
Posts : 14
Join date : 2012-03-30

Re: Finding element by content with scLocator?

on Tue Apr 10, 2012 8:02 pm
This xpath didn't work, but I managed to get dropdown list with

But, I just can't manage to fetch all elements in the list.
I tried with selenium.getAllFields(...) but obviously it's not the correct command, since the result list is null. I would like to get at least the number of items in the list, because then I could iterate through the list and get the element I need like this:
def elem = selenium.getText("scLocator=//DynamicForm[ID=\"isc_DynamicForm_0\"]/item[name=type]/pickList/body/row["+i+"]/col[0]");
if (elem == "External") {
  print "External selected.\n"

Can you help me to get number of fields in dropdown list? Thanks in advance Smile
Sponsored content

Re: Finding element by content with scLocator?

Back to top
Permissions in this forum:
You cannot reply to topics in this forum