How to do mouse hover in geb spock

learn automation with geb and spock
geb timeout
geb pause
spock waitfor
geb xpath
geb spoke
geb-testng
geb logging

I am using geb spock and trying to hover an element, however I am getting error. Below are details. Page Object Class

class HomePage extends Page {

    static at ={
        title.contains("Activity Dashboard")
    }

    static content = {
        tabConnections (wait : true) {$("a", "class" : contains("dropdown-toggle"), "text" : "Connections")}
        subMenuManageConnections (wait: true) {tabConnections.find("ul").find("a" , "href": "/managecash/EDGE_Network" , "text" : "Manage Connections")}
    }


    public void mouseHoverMethod(){
        waitFor {tabConnections.displayed}

        Actions actions = new Actions(driver)
        actions.moveToElement(tabConnections).build().perform()
    }
}

When I am calling mouseHoverMethod method from my spock spec file, getting below error message: on line (actions.moveToElement(tabConnections).build().perform()) as below:

Error Message:

groovy.lang.MissingMethodException: No signature of method: org.openqa.selenium.interactions.Actions.moveToElement() is applicable for argument types: (geb.content.TemplateDerivedPageContent) values: [pageobjects.general.HomePage -> tabConnections: geb.navigator.NonEmptyNavigator] Possible solutions: moveToElement(org.openqa.selenium.WebElement), moveToElement(org.openqa.selenium.WebElement, int, int)

Can you please help me how mouse hovering can be done in Geb Spock?

The error message tells you that you are providing a TemplateDerivedPageContent instance (tabConnections) to the moveToElement() method. But if you check the method's signature you see that is expects a WebElement argument. Of course Selenium WebDriver does not know anything about Geb-specific classes. Thus, you have to get the web element from your navigator like this:

actions.moveToElement(tabConnections.firstElement()).build().perform()

Geb Programmer : Hidden Content and Mouse over Events, The error message tells you that you are providing a TemplateDerivedPageContent instance ( tabConnections ) to the moveToElement()  3 How to do mouse hover in geb spock May 20 '18 2 How to take screenshots only for failure step in geb using athaydes plugin May 11 '18 2 Not able to skip blank lines in a shell script May 4 '18

You could also use Geb's interact block, see http://www.gebish.org/manual/current/#complex-interactions

Your method would then look like ->

public void mouseHoverMethod(){
    waitFor {tabConnections.displayed}
    interact {
        moveToElement(tabConnections)
    }
}

1.0, Geb Programmer : Hidden Content and Mouse over Events. 28 / 07. Leave a reply. Lets say we have an HTML page with content hidden until we place the mouse over it. to include Jquery and execute a Jquery method to make the paragraphs visible. Geb Programmer : User Agent Spoofing Spock Programmer : Setup  Lets say we have an HTML page with content hidden until we place the mouse over it. It will look like this: And this is the html If I try to fetch the content with Geb, it will fail because it is h…

@kriegaex, @erdi. Thanks for your solutions. I am also able to find one working solution and created below methods in page object. All three methods are working fine.

public void mouseHoverMethodOne (TemplateDerivedPageContent element){
        waitFor {element}
        element.jquery.mouseover()
        element.click()
    }

public void mouseHoverMethodTwo (TemplateDerivedPageContent element){
        waitFor {element.displayed}
        Actions actions = new Actions(driver)
        actions.moveToElement(element.firstElement()).build().perform()
        element.click()
    }

public void mouseHoverMethodThree (TemplateDerivedPageContent element){
        waitFor {element.displayed}
        interact {
            moveToElement(element)
        }
        element.click()
    }

Thanks for your help on this. I have rated your answers too, as those give me lot of insights.

Complex UI elements in Geb browser tests, Examples of interacting with complex UI elements in Geb browser Geb provides an interact block that we can use to drive the mouse using Maybe something like a mouse-over menu that is tricky to hover over in a test. Integration with the Spock Testing Framework. Spock is one of the most popular testing frameworks for the Groovy language. And Geb comes with an excellent integration for Spock. I won’t go through the details of configuring Geb and Spock in a maven (or gradle) project. Detailed instructions, how to do this, can be found in the Book of Geb.

How to Verify Tooltip using Selenium WebDriver, The tooltip is a text that appears when a mouse hovers over an object like a link, an image, How to get Tooltip Text in Selenium Webdriver. You may follow the below steps to disable the mouse hover feature in windows 10 and check if it helps: 1. Right click on Start menu. 2. Click on Control Panel. 3. In the control panel window, select “Ease of Access Centre” option. 4. Click on “Make mouse easier to use”. 5.

End-to-end testing with geb, So, we have work to do 3 or 4 most tested pages are already converted to Page Why geb Concise Team already using Groovy with Spock for tests Standard, tested aVariable == 1 $("div#a").jquery.mouseover(); 36. Geb in  This video will guide you How to Scroll Inside a webelement in Selenium Webdriver using Java Script Executor. Selenium support auto scroll to find an element but sometimes we need to scroll based

spock - Python, How to do mouse hover in geb spock · How to take screenshots only for failure step in geb using athaydes plugin · What is the purpose of Spock's #Unroll  I wanted to know if we can use Geb and spock framework for windows application automation testing? If yes, then please suggest the suitable tools that can be used with Geb & Spock framework for windows application automation testing.

Comments
  • Note that moveToElement() inside of interact {} blocks takes a Navigator as the first argument so there is no need to call firstElement() on tabConnections and the call can be simplified to moveToElement(tabConnections).
  • Updated per erdi's advice. Thanks :)
  • Welcome. Maybe instead of just copy & paste harvesting solutions into your threefold recap you could just accept one of the answers offered. Whether you do "first come, first serve" or like to pick another favourite is up to you, of course.