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?

Nick Kahn
  • 19,652
  • 91
  • 275
  • 406
  • 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. – Ardesco Apr 04 '13 at 07: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. – Nick Kahn Apr 04 '13 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? – Nick Kahn Apr 04 '13 at 13:35
  • Is the page publicly visible? – Ardesco Apr 04 '13 at 15:33
  • no its not unfortunate – Nick Kahn Jul 09 '13 at 14:36
  • Can you supply an HTML snippet of the image you are hovering over with its associated CSS? – Ardesco Jul 09 '13 at 15:30

4 Answers4

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.

Antony
  • 14,900
  • 10
  • 46
  • 74
e1che
  • 1,241
  • 1
  • 17
  • 34
4

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

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

Chris Bier
  • 14,183
  • 17
  • 67
  • 103
bugCracker
  • 3,656
  • 9
  • 37
  • 58
  • That link is helpful but an additional quick summary in your answer would be very helpful to the reader – sebisnow Sep 11 '19 at 12:34
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();
khr055
  • 28,690
  • 16
  • 36
  • 48
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();