1

I have a query on mouseover action in Selenium Webdriver Java.

Consider i have a background image with id "Lfade" with opacity 0.5. If i hover the mouse then a button would be shown.

I want to click on the button to take me to another screen. How do i do this ???

I have tried this, but it does not work

Actions builder = new Actions(driver);
WebElement tagElement = driver.findElement(By.id("Lfade"));
builder.moveToElement(tagElement).build().perform();

Html

div id="homeslant"
div id="wrapper"
div id="lFade" class="learn" style="opacity: 0.5; visibility: visible;"

Button

div class="descbtn"
a class="btn dwmbutton" href="/learn/index.html">KNOW MORE</a>
1

6 Answers 6

2

Not sure about what you are trying to do but I notice an error here:

builder.moveToElement(tagElement).build().perform();

Actually, the .perform() includes a .build().

May be you were referring to .click() so

builder.moveToElement(tagElement).click().perform()

As a pattern for your objective I would:

  • find the first image
  • move to the image
  • wait
  • find the button
  • click the button
Sign up to request clarification or add additional context in comments.

1 Comment

It is like Mac dock. Dock would be hidden and when mouse is pointed near dock area the dock area would appear. Similarly in my case the button would appear only when user moves the mouse to that image. As you move the mouse to that image the button would appear.
0

I used Robot class for mouse hover. Please try the below code.

Robot robot = new Robot(); Point MyPoint = tagElement.getLocation(); robot.mouseMove(MyPoint.getX(), MyPoint.getY());

After that use the normal selenium click to click on the button.

Comments

0

You need to move to the button and perform a click.

  1. Move to the image
  2. wait
  3. Move to the button and click

    Actions act = new Actions(driver); WebElement tagElement = driver.findElement(By.id("Lfade")); act.moveToElement(tagElement).click().build().perform(); WebElement _button= driver.findElement(By...); act.moveToElement(_button).click().build().perform();

Comments

0

Try this

@FindBy(xpath="//*[@id='chromemenu']/span/a") WebElement menuHoverLink;
@FindBy(xpath="//*[@id='dropmenu1']/a[1]") WebElement subLink;
Actions maction = new Actions(driver);
maction.moveToElement(menuHoverLink).build().perform();
Thread.sleep(2000);
subLink.click();

Comments

0

Use this code it will work :

Actions builder = new Actions(driver);
WebElement tagElement = driver.findElement(By.id("Lfade"));
WebElement buttonElement = driver.findElement(By.classname("btn"));
builder.moveToElement(tagElement).moveToElement(buttonElement).click().perform();

Comments

0

Try this

public void HoverAndClickObject(WebDriver driver, String property1, String property2, String path) throws SAXException, IOException, ParserConfigurationException
        {
            //get object properties from the xml file repository
            Actions action = new Actions(driver);
            String[] element1 = xmlParser(path, property1);
            String[] element2 = xmlParser(path, property2);
            switch (element1[0].toUpperCase())
              {
                  case "XPATH":
                      driver.findElement(By.xpath(element1[1])).click();    
                      action.moveToElement(driver.findElement(By.xpath(element2[1]))).click().build().perform();
                      break;

                  case "ID":
                      driver.findElement(By.id(element1[1])).click();
                      break;

                  case "NAME":
                      driver.findElement(By.name(element1[1])).click(); 
                      break;

                  case "LINKTEXT":
                      driver.findElement(By.linkText(element1[1])).click();
                      break;

                  case "CSSSELECTOR":
                      driver.findElement(By.cssSelector(element1[1])).click();
                      break;

              }


        }

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.