Kiddo
Kiddo

Reputation: 1990

Selenium Click Outside Element (button)

I'm running into the problem that I need to click on the expanded functions of an Element which is triggered by JS.

Picture to illustrate the UI: https://i.sstatic.net/SlJjz.jpg

So when I hover over the blue button, it will display 3 other shapes at the bottom. Those shapes'html code won't show until mouse is hovering on it. My approach was to use actions chain to hover over the blue button element then click off that element (in which way i can click on the 3 shapes below).

So far I have:

    Actions action = new Actions(driver);
    action.moveToElement(elementPosition).build().perform();
    action.moveToElement(elementPosition, offsetx, offxety).click();

But I cannot click Offset the element, is it a proper way to do it? Thank you

Upvotes: 1

Views: 5907

Answers (1)

Tom Trumper
Tom Trumper

Reputation: 472

Are you able to retrieve the HTML code for the three buttons once you have made them visible? If so, you should be able to find and click them using WebDriver.findElement() and WebElement.click() respectively.

For example:

// Find the blue button
WebElement blueButton = driver.findElement(By.id("blue"));
// Hover over the blue button
Actions action = new Actions(driver);
action.moveToElement(blueButton).build().perform();

// Find the red button
WebElement redButton = driver.findElement(By.id("red"));
// Click the red button
redButton.click();

// And so on...

In this example, it is imperative that you attempt to find the red button after the blue button has been hovered over.

Upvotes: 0

Related Questions