7

EDIT:

okay, i have checked the code and its rendering out by a jquery widget.

END

I am trying to move the cursor to <a \>, but the problem is that the element is not rendered until i move mouse pointer physically on selected image.

How can i move to the mouse to hover over <a \> to select/click?

FF version 20
Selenium WebDriver version: 2.31.2.0

Current code

 Actions actions = new Actions(driver);

 int locationX = Convert.ToInt32(ratingElementDiv[i].Location.X);
 int locationY = ratingElementDiv[i].Location.Y;

 actions.MoveToElement(WaitForElement(By.CssSelector(starElement)), locationX, locationY).Click().Perform();

i dont see any action happening... any help?

6
  • 1
    Is the hover event triggered by a CSS :hover event? If so are you using a non-native events (e.g. FireFox in OSX). If the answer to the two previous questions is yes you are stuck, JavaScript cannot trigger a CSS :hover event you need a native implementation. Commented Apr 4, 2013 at 7:58
  • 1+ thanks for the info, i have to check to see if the hovering is happening in css, i will get back to you. Commented Apr 4, 2013 at 13:12
  • okay, i have checked the code and its rendering out by a jquery widget... so in this case what should i be doing? Commented Apr 4, 2013 at 13:35
  • Is the page publicly visible? Commented Apr 4, 2013 at 15:33
  • no its not unfortunate Commented Jul 9, 2013 at 14:36

4 Answers 4

8

Action is composed by 3 steps.

  • configuration
Actions builder = new Actions(driver); 
Point location ratingElementDiv[i].getLocation(); 
builder.MoveToElement(WaitForElement(By.CssSelector(starElement)), location.X, location.Y).click();

(i'm not sure about the click)

  • get the action
Action selectLink = builder.build();
  • execution
selectLink.perform();

try this and tell me if you still have some problem.

Sign up to request clarification or add additional context in comments.

3 Comments

error: on builder.Build() - Cannot implicitly convert type 'OpenQA.Selenium.Interactions.IAction' to 'System.Action'
I use org.openqa.selenium.interactions.Actions i can't help you more i don't really know something about jquery ;(
is it possible to have the html ?
4

This link will help you. It explain both keyboard and mouse event.

http://www.guru99.com/keyboard-mouse-events-files-webdriver.html

1 Comment

That link is helpful but an additional quick summary in your answer would be very helpful to the reader
3

Lets say when you click "Select Your Test" you see a dropdown of multiple elements(ABC, DEF, GHI, etc ). You want to select ABC and click it. Use following.

driver.findElement(By.linkText("Select Your Test")).click();
new Actions(driver).moveToElement(driver.findElement(By.linkText("ABC"))).click().perform();

Comments

0

it works to me

//定位一個按鈕
WebElement button = driver.findElement(By.xpath("//div[@class='page-button']"));
//new 一個移動滑鼠的物件
Actions clickAction = new Actions(driver).click(button);
//執行
clickAction.build().perform();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.