Robot Framework + Selenium and DOJO

580 views
Skip to first unread message

Richard Shy

unread,
Oct 25, 2011, 5:36:04 AM10/25/11
to robotframework-users
Does anybody here have experience using Robot Framework + Selenium to
test UI developed using DOJO?

I saw an old thread about this but it did not have details.
http://groups.google.com/group/robotframework-users/browse_thread/thread/a6b22d88cfdd8613?pli=1

I was hoping that someone could help me with this. I want to click on
an element, particularly a link within a DOJO table but Robot says it
can't find it. I've tried different ways of clicking that element
(using xpath, css) but to no avail.

I'm attaching a screenshot of the thing I'm testing.

http://images.plurk.com/a999411b419d24cfdc675f3505cb9478.jpg

Any help or suggestion would be greatly appreciated. Thanks!

David

unread,
Oct 25, 2011, 7:29:19 PM10/25/11
to robotframework-users
Are you sure you clicked the right element as defined by XPath or CSS?
One thing about Dojo and other AJAX libraries is that their elements
are tricky to work with. What you see may not be what you want. There
could be hidden elements that are the ones you actually want to
manipulate.

In my case, there was a DOJO drop down menu widget, where the actual
value to select was in a hidden form field rather than the drop down
menu. The menu was just a UI, the actual data was stored in hidden
field that the menu then made use of behind the scenes. You could read
the value from the menu element but to set the value, you had to set
the hidden field rather than the menu. Setting menu had no effect.

I'm guessing you've run into a similar problem. So you need to find
out what the actual element to manipulate really is. Hopefully your
developers might have some idea. Or keep trying with Firebug and
Selenium, and poking through HTML source code until it works.

On Oct 25, 2:36 am, Richard Shy <richard....@gmail.com> wrote:
> Does anybody here have experience using Robot Framework + Selenium to
> test UI developed using DOJO?
>
> I saw an old thread about this but it did not have details.http://groups.google.com/group/robotframework-users/browse_thread/thr...

David

unread,
Oct 25, 2011, 7:38:54 PM10/25/11
to robotframework-users
> I'm attaching a screenshot of the thing I'm testing.
>
> http://images.plurk.com/a999411b419d24cfdc675f3505cb9478.jpg
>
> Any help or suggestion would be greatly appreciated. Thanks!

Also, looking at your screenshot, make sure your XPath's are optimal.
What Firebug and related addons return to you are sometimes not very
descriptive XPaths and you have to refine them.

And Dojo and similar libraries may have notoriously complex table
grids. Bear in mind you have multiple rows and must select correct
table row, or else XPath will match all rows and Selenium won't know
which of the many links to click. I had to do something like this to
narrow down to desired row for row i:

xpath=(//table/tbody/tr/td[8]/div/a[text()='delete'])[i]

and get a specific image in table like this

xpath=(//table/tbody/tr/td[4]/div/img)[1]

Richard Shy

unread,
Oct 25, 2011, 10:31:09 PM10/25/11
to robotframework-users
Hi David,

Thanks for the reply.

I think I'm clicking the right element since I've used several tools
to identify the element. I can't seem to inspect the table area (right
click -> inspect element), which is the DOJO part of the code, both in
Firefox and Chrome. In order to get the xpath and css path, I used the
Selenium IDE plugin for Firefox and an xpath extractor extension on
Chrome. I tried plugging in the values into my Robot tests but it
still couldn't find the element. Do correct me if I'm doing something
wrong because this is the first time I've worked with DOJO and I am
absolutely clueless about it.

Looking at your subsequent reply, I'd be willing to try that out. What
was the original xpath that you got, and how did you refine it?

David

unread,
Oct 26, 2011, 1:01:44 AM10/26/11
to robotframework-users
Richard, the examples I provided I think is pretty much what I got
from Firebug and related extensions, except for the hyperlink element
where I added text()='delete' to better define it.

Though I typically don't take the XPath generated from the extensions.
I inspect the element to see the HTML source around it and then
backtrack up the source tree to see how I can then best define the
XPath based on element text and attributes rather than a nesting of
element types (w/o attributes and element text) that you get from the
browser plugins. But in the case of DOJO table grids, you don't really
get much uniqueness other than some random IDs for attributes, so you
may have to use the nested element method like my example XPaths.

But what I learned from searching online is that when you get multiple
matches for an XPath that you can't refine any more and you only want
a particular match out of the set, you have to enclose the XPath in
parenthesis like in my examples, then append node position for the
exact one you're interested in. You can loop through with an index
variable for position if need to process them all one at a time. I
believe Selenium can't handle a set, so you have to process one at a
time. If you leave out the parenthesis, and just append position to
XPath, Selenium may have issues finding the element. I forget where I
found that info online, it's been a while.

磁针石

unread,
Oct 26, 2011, 9:08:32 PM10/26/11
to robotframework-users
I have met dojo too. and the id is dynamic. Our label is static. So I
first capture HTML source, then use python dict to record each id and
related label. Thus we use label to recognize element. Has anyone some
good idea?

Richard

unread,
Oct 27, 2011, 2:53:51 AM10/27/11
to robotframework-users
Hey David,

I tried enclosing the xpath in parenthesis and it seemed to work for
me. I don't know if this will be a long term solution but I appreciate
the suggestion. I will read into optimizing xpaths to understand it
better.

Thank you very much!

On Oct 26, 1:01 pm, David <manga...@gmail.com> wrote:
Reply all
Reply to author
Forward
0 new messages