0

I am writing tests for a Java application which has been developed using the Vaadin framework. For the tests I am using Robot Framework. At some steps I have to use robot framework commands like execute javascript.

For example, for finding a component I have to execute the following command:

execute javascript    document.getElementById('button-create').click()

Which works without any problem. Primitives like Click Element are not working because Vaadin doesn't wait until the whole page is loaded and therefore some ids are not yet assigned at run time.

Unfortunately this application has been developed in such a way that some components are not reacting to the event click but to the event mousedown. That is, at the Java console of chrome I can perform the following command:

    document.getElementsByClassName('table-cell-wrapper')[1].mousedown();

and the action is performed without any problem. So far so good.

Unfortunately when trying to do the same at robot framework

    execute javascript    document.getElementsByClassName('table-cell-wrapper')[1].mousedown();

I am getting te following error:

Executing JavaScript:
document.getElementsByClassName('table-cell-wrapper')[1].mousedown();
20131029 12:22:12.445 :  INFO : </td></tr><tr><td colspan="3"><a href="selenium-    screenshot-1.png"><img src="selenium-screenshot-1.png" width="800px"></a>20131029 12:22:12.453 :  FAIL : 
WebDriverException: Message: u'document.getElementsByClassName(...)[1].mousedown is not a function' ;

Then the question is... how can I trigger the event mousedown on a given element using Javascript and Webdriver.

My environment is:

RIDE 1.2.1 running on Python 2.7.5. 
Robot Framework 2.8.1
Library           Selenium2Library
Library           Screenshot
Library           Dialogs
Library           Collections

Thanks in advance.

Luixv
  • 8,590
  • 21
  • 84
  • 121
  • Do you have to use Robots? What's wrong with standard Selenium commands, or the javascript commands you were using? – Nathan Merrill Oct 29 '13 at 13:33
  • As I said the application is written using Vaadin. This framework doesn't wait until the complete page is loaded. Therefore at running time id are not yet assigned and you cannot find the elements for clicking (or mousedown). – Luixv Oct 29 '13 at 13:36

1 Answers1

0

From Selenium2Library Execute Javascript keyword:

Note that, by default, the code will be executed in the context of the Selenium object itself, so this will refer to the Selenium object. Use window to refer to the window of your application, e.g. window.document.getElementById('foo')

So you might want to put window. in there.

mousedown() is not a pure Javascript function. JQuery does have one and there is a event called mousedown in plain JS also.

If some element does not exists after the page is loaded causing

Click Element    foobar

to fail, you can use Wait Until Page Contains Element and then click that element. You could write your own Press Element keyword to make it more usefull:

Press Element    ${locator}
    Wait Until Page Contains Element    ${locator}
    Click Element    ${locator}
Harri
  • 2,692
  • 2
  • 21
  • 25
  • Thanks for your answer but no, the problem is not the "window" reference. I've already put some "wait until page contains" and this is not solving the problem. I have to perform a "mouse down" at an element and I don't know how. – Luixv Oct 29 '13 at 20:54
  • I'm fairly sure that simulating mousedown through execute javascript will not make any difference compared to my press element approach but here you go http://stackoverflow.com/questions/4158847/is-there-a-way-to-simulate-key-presses-or-a-click-with-javascript. And if JQuery is in use window.$('.wrapper').mousedown() will do. – Harri Oct 29 '13 at 21:14