1

I'm trying to click on a CSS menu, first I need to hover over and then click a sub menu link I am able to do this when i run my test as an individual or a JUnit test, but when I run the same test from ant(I have created a batch file used to run the tests) hover does not work.

code for hovering and click on a sub menu link

String menuhoverlink = "//*[@id='orders']/a";    
String sublink = "//*[@id='orders']/ul/li[4]/a";    
Actions builder = new Actions(driver);    
builder.moveToElement(driver.findElement(By.id(menuhoverlink))).build().perform();    
driver.findElement(By.id(menuhoverlink))
  1. I need to understand why hovering and clicking on a sub menu link does not work when I run the test using ant?
  2. How to solve this issue?

Thanks in advance..!!

Mark O'Connor
  • 76,015
  • 10
  • 139
  • 185

1 Answers1

0

First of all, menuhoverlink and sublink are not ids and you are using By.id()to locate them which is wrong.

Use `By.xpath()`

Second, you never performed any click()on the element. Something following should work.

String menuhoverlink = "//*[@id='orders']/a";    
String sublink = "//*[@id='orders']/ul/li[4]/a";    
Actions builder = new Actions(driver);    
builder.moveToElement(driver.findElement(By.xpath(menuhoverlink))).build().perform();    
driver.findElement(By.xpath(sublink)).click();

See here for similar options including javascript

Community
  • 1
  • 1
Saifur
  • 16,081
  • 6
  • 49
  • 73
  • Hi Saifur, Thanks for your comments, i am able to hover and click on elements when i run the Junit test directly from eclipse. The problem is when i run the same test using ant hover does not work. I need to know what is the difference when we directly run Junits. tests from eclipse and running Junit tests from ant. Should i include any task or target in my build.xml to make sure hover will work i run the Junit tests through ant? – user3911901 Dec 25 '14 at 20:27
  • @user3911901 I am afraid the original code is wrong. I am not sure how that works. – Saifur Dec 25 '14 at 20:45