Selenium2Library Click Element from specific coordinates

4,444 views
Skip to first unread message

Tatu aalto

unread,
Oct 24, 2012, 10:33:23 AM10/24/12
to robotframe...@googlegroups.com
Ugh

I have element in my web page, which enables user to zoom in and out. One can think it as a route on the map. Now in my application, when zoomed in, user can influence the route with greater detail. Where the zooming goes, is determined by the place where user clicks on the map/element.

But this causes a challenge in Selenium2Library. The only way click the element is to use Click Element keyword and by default and it seems to click on the middle of the element. Is it somehow possible to adjust where in the element the Click element keyword clicks? If not, can/how should I create a new keyword, which enabled me to click on the desired place/coordinates.

-Tatu

Kevin O.

unread,
Oct 25, 2012, 11:59:24 AM10/25/12
to robotframe...@googlegroups.com
I have no experience in doing what you are trying to do, but it looks like you will have to go down to the WebDriver API to do what you want.
The action_chains API has some promising methods (e.g. using move_to_element_with_offset and click(None)): http://selenium.googlecode.com/svn/trunk/docs/api/py/webdriver/selenium.webdriver.common.action_chains.html
I found an example of how to use action chains in Python here: http://stackoverflow.com/questions/11092748/how-to-mouseover-in-python-webdriver
There are examples in this group how to get the instance of WebDriver in user and library(Python) keywords.
From what I saw I would not expect it to work on all platforms or browsers, though.

Good luck,
Kevin

Tatu Aalto

unread,
Oct 26, 2012, 5:33:24 AM10/26/12
to korm...@gmail.com, robotframe...@googlegroups.com
Ugh

Thanks for help. When running only with selenium, this code seems to do
the trick:
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains

#driver = webdriver.Chrome()
driver = webdriver.Firefox()

driver.get("URL-HERE")

element = driver.find_element_by_xpath("XPATH-HERE")

ActionChains(driver).move_to_element(element).move_by_offset(300,
100).click().perform()

By looking Selenium2Library code (first time for me), it would seem fair
easy to implement this. Because the code seems really clear also for a
tester eyes.

But it has an limitation. It runs fine with Chrome but in Firefox get
stack trace. I did not try IE, because our SUT lives in a linux world. I
see this trace when executing above line of code in Firefox:

Traceback (most recent call last):
File "test.py", line 45, in <module>
ActionChains(driver).move_to_element(chartStabs).move_by_offset(-300,
-100).click().perform()
File
"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/action_chains.py",
line 44, in perform
action()
File
"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/common/action_chains.py",
line 190, in <lambda>
'yoffset': yoffset}))
File
"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py",
line 156, in execute
self.error_handler.check_response(response)
File
"/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py",
line 147, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: u'Element cannot
be scrolled into view:[object HTMLImageElement]'

Because it seems to be pure selenium issue and when looking selenium
user group, other people have had similar problems [1]. The workaround

I could write patch for Selenium2Library, but it would work only in
Chrome. Would it be acceptable?

-Tatu

[1] http://code.google.com/p/selenium/issues/detail?id=2067
> --
> You received this message because you are subscribed to the Google
> Groups "robotframework-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/robotframework-users/-/6NWwK5SCX4IJ.
> To post to this group, send email to
> robotframe...@googlegroups.com.
> To unsubscribe from this group, send email to
> robotframework-u...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/robotframework-users?hl=en.

Tatu aalto

unread,
Oct 26, 2012, 11:19:16 AM10/26/12
to korm...@gmail.com, robotframe...@googlegroups.com

Ugh

Well the error was caused because I did click out of the element. Strange that it does not complain in Chrome. But it does not work with Firefox. With Firefox it always clicks on the middle of the element.

But I did made the patch and a acceptance test case for it. But when I run the test the test passes but the report is marked as failing. Could some-one provide some pointers how the acceptance test should be build for Selenium2Library?

-Tatu

To post to this group, send email to robotframework-users@googlegroups.com.
To unsubscribe from this group, send email to robotframework-users+unsub...@googlegroups.com.

Ed Manlove

unread,
Oct 26, 2012, 1:12:20 PM10/26/12
to aalto...@gmail.com, robotframe...@googlegroups.com
Tatu,

There is a little bit of information within the developer information doc - BUILD.rst  [1] about the internal acceptance and unit tests. And there are the tests themselves for which you can find some related acceptance tests within

  https://github.com/rtomac/robotframework-selenium2library/blob/master/test/acceptance/keywords/click_element.txt

You could either add the patch and test to an issue or submit a pull request from your clone repository.

Also Tatu, if I may ask, is the term "Ugh" a greeting?  I have seen it used in this forum before but I am sorry to say I'm a little ignorant of it's meaning.  Thank you for helping me learn more.

Ed

[1] https://github.com/rtomac/robotframework-selenium2library/blob/master/BUILD.rst
To post to this group, send email to robotframe...@googlegroups.com.
To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.

For more options, visit this group at http://groups.google.com/group/robotframework-users?hl=en.
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To post to this group, send email to robotframe...@googlegroups.com.
To unsubscribe from this group, send email to robotframework-u...@googlegroups.com.

Jussi Mononen

unread,
Oct 26, 2012, 1:42:56 PM10/26/12
to devP...@verizon.net, aalto...@gmail.com, robotframe...@googlegroups.com
On 26 October 2012 20:12, Ed Manlove <devP...@verizon.net> wrote:
> Also Tatu, if I may ask, is the term "Ugh" a greeting? I have seen it used
> in this forum before but I am sorry to say I'm a little ignorant of it's
> meaning. Thank you for helping me learn more.

Hi,

at least in Finnish comics the term "Ugh" has been used as a greeting
of native American Indians. I'm pretty sure that it does not signify
"boredom" as defined in the Urban Dictionary [1] :-)

-jussi

[1] http://www.urbandictionary.com/define.php?term=Ugh

--
"Progress doesn't come from early risers — progress is made by lazy
men looking for easier ways to do things." - Robert A. Heinlein
[ http://www.agile.fi - http://www.agilefinland.com -
http://www.scan-agile.org ]
[ http://www.jussimononen.org - http://www.twitter.com/agilepoodle ]

Tatu Aalto

unread,
Oct 27, 2012, 2:50:49 PM10/27/12
to jussi....@iki.fi, Jussi Mononen, devP...@verizon.net, robotframe...@googlegroups.com
Ugh

The new keyword:
Thanks for the tips. I did found what was making the test fail. It was
the wrong documentation in the test. It seems that the test
documentation is used for compare the first keyword in the test. When I
fixed that, report.html did go green.

I did create a patch for the new keyword, but I do not understand how
this githup works. Where do I send it and how?

For the second question:

Jussi did got it right. The comic in question in my case was the Donald
Duck. When I was younger, I though it would cool to start letters (you
know the ones written in paper with hand) like that. Well, anyway when
the change to email did come, the same greeting did stuck.

It was years later, when I did learn that it means also boredom. But am
too stubborn to change the greeting of my emails. And do not worry, you
are not first one to ask from it and I am pretty sure that you are not
the last one :-)

-Tatu
click_element_at_coordinates.patch

Pekka Klärck

unread,
Oct 29, 2012, 6:36:28 AM10/29/12
to aalto...@gmail.com, robotframe...@googlegroups.com
2012/10/27 Tatu Aalto <aalto...@gmail.com>:
>
> I did create a patch for the new keyword, but I do not understand how this
> githup works. Where do I send it and how?

GitHub uses "pull requests" for this purpose. That's a lot better
approach than sending patches and the main reason we plan to move
Robot itself either to GitHub or BitBucket some time in the nearish
future.

For more information about pull requests in general and how they are
used in GitHub see:
https://help.github.com/articles/using-pull-requests

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Tatu Aalto

unread,
Oct 30, 2012, 4:15:33 AM10/30/12
to Pekka Klärck, robotframe...@googlegroups.com
Ugh

Thanks from the pointers, doing it by yourself gives good view how this
git works. I did send a pull request to the origin and it is waiting
comments.

-Tatu
Reply all
Reply to author
Forward
0 new messages