StevenB
StevenB

Reputation: 21

Selenium via Eclipse: is it possible to move the cursor position?

I am using the selenium plug in for eclipse to automate the testing of newly created websites. I am trying to click a button that is in a menu and only visible when the cursor is located over the menu.

Is it possible to move the cursor so that this button can be clicked ?

Upvotes: 2

Views: 1658

Answers (2)

ernie
ernie

Reputation: 6356

It's unclear if you're using Selenium RC or Selenium 2 and WebDriver.

I can only speak to the latter, but you can use Actions to move the mouse and click. The basic idea is you define an object that is a series of actions, and then you perform those actions.

An introduction on how to use these is at http://code.google.com/p/selenium/wiki/AdvancedUserInteractions, and a good writeup with Python examples is http://www.theautomatedtester.co.uk/blog/2011/selenium-advanced-user-interactions.html

It sounds like in your case, you would have something like:

Actions menuClick = new Actions(driver);

builder.MoveToElement(menuElement)
    .MoveToElement(buttonElement)
    .click(buttonElement)

Action menuClick = builder.build();

menuClick.perform();

Upvotes: 0

borrible
borrible

Reputation: 17376

It will depend a little on how the menu has been implemented (i.e. the event that will trigger your button to appear) but you should look at the focus and mouseOver methods for selenium.

I.e. do something like

this.selenium.mouseOver(element);

where element refers to the menu and then do a click on the button. If mouseOver does not work (i.e. the button does not become available) try focus instead.

Upvotes: 1

Related Questions