Search code examples
rubycursorselenium-webdriver

How to get a Mouse Cursor Type?


I am currently testing a web application and facing a problem. I need to know what type of cursor now to open the context menu. It's impossible to find an element that can be context (right mouse button) clicked on, I can only track the cursor type.

For example. if you move your cursor over a link it turns into a hand; or when you move your cursor over textfield it turns into "I". I need to know when the cursor has changed.

Do you have any ideas, how can I do this?


Solution

  • Selenium can only query things in your browser, and the cursor display is controlled by your OS.

    The best I can suggest would be to check the CSS cursor attribute value using:

    function String getElementCursorType(WebElement element) {
        return element.getCssValue("cursor");
    }
    

    See http://www.w3schools.com/cssref/tryit.asp?filename=trycss_cursor for a list of possible return values and a live demo to see the actual cursor used by your system.