Issue in finding element on a webpage

501 Views Asked by At

The id for webelement is mainPage:mainForm:j_id152:locationsPage:locsBlock:slTable:0:locNamePanel

The problem is:

To find a WebElement. When hovered upon that webelement, Edit link comes up which needs to be clicked.

Tried this approach:

  1. Scrolling the webpage down (just in case)
  2. Finding the webElement by id
  3. Getting the X and Y coordinates for that webElement
  4. Using mouseover

Following is the code:

//Finding the Webelement coordinates
int X= driver.findElement(By.id("mainPage:mainForm:j_id152:locationsPage:locsBlock:slTable:0:locNamePanel")).getLocation().getX();
int Y= driver.findElement(By.id("mainPage:mainForm:j_id152:locationsPage:locsBlock:slTable:0:locNamePanel")).getLocation().getY();
System.out.println("The coordinates are:-" +X +"---"+Y);
Robot robot = new Robot(); 

//Doing a mouse over for the X and Y coordinates
robot.mouseMove(X, Y);

//Clicking the Edit button
driver.findElement(By.id("mainPage:mainForm:j_id152:locationsPage:locsBlock:slTable:0:j_id207")).click();

Issue:

The X and Y coordinates are coming back (not sure if those are for the WebElement that I am looking for). But, the mouseover isn't working.

1

There are 1 best solutions below

0
On

Why wouldn't you do something like the following:

//Finding the WebElement
WebElement element = driver.findElement(By.id("mainPage:mainForm:j_id152:locationsPage:locsBlock:slTable:0:locNamePanel"));
Actions actionsProvider = new Actions(driver);
actionsProvider.moveToElement(element).perform();

//Clicking the Edit button
driver.findElement(By.id("mainPage:mainForm:j_id152:locationsPage:locsBlock:slTable:0:j_id207")).click();

This should accomplish the same thing without having to rely on the Java Robot classes.