Unable to click or hover mouse on a Span element
Issue: Using .Click() or .HoverMouse() is not working for 1 of the webelements of the type [HTMLSpanElement]. Error thrown is: TypeError: webObj.HoverMouse is not a function OR TypeError: webObj.Click() is not a function
Description: I need to either mouse hover or click on an element which looks like a button named as Panel Menu. This opens a a menu in which I should click on 1 of the options from the menu. PFA the screenshot - PanelMenu. This shows the webelement - Panel Menu on which I need to either Hover the mouse or click, so that it opens up the menu as shown. After that I need to click on Align Panels option within the menu. PFA the screenshot - PanelMenuElementInfo. This contains the HTML element details of it. I am using JavaScript to write a test script.
Code snippets (tried below options but no luck):
//Clicking the object
let webObj = this.getPanelMenuObj() //This returns the webelement of type [HTMLSpanElement]
webObj.Click(); //Just a normal click function which throws the error
//Mouse hover on the object
let webObj = this.getPanelMenuObj() //This returns the webelement of type [HTMLSpanElement]
let width = webObj.width
let height = webObj.height
let destX = (width/2) - 2
let destY = (height/2) - 2
webObj.HoverMouse(destX,destY);
The above approach had the the issue - Width and height was returning undefined value. So, I tried to hardcode the height and width by taking the values of height and width from the element's style attribute.
let webObj = this.getPanelMenuObj() //This returns the webelement of type [HTMLSpanElement]
let width = 81
let height = 27
let destX = (width/2) - 2
let destY = (height/2) - 2
webObj.HoverMouse(destX,destY);
This approach again throws the error: TypeError: webObj.HoverMouse is not a function.
NOTE: I tried to have a for loop which waits 1000 ms each time for the width of the web object to load the actual value. I looped for 25 times and every time it returned width as undefined.
Please help! Let me know if any other details are required!
Perhaps the Panel menu is an object drawn directly on screen (onscreen object).
To check that use the object from point method.
To click on this kind of object you can use my method with a call like clickInObject("screen", x,y).
Hi,
> Error thrown is: TypeError: webObj.HoverMouse is not a function OR TypeError: webObj.Click() is not a function
This is a clear indication that webObj is not a wrapping object provided by TestComplete (as a result of FindXXX() call or using the Aliases). Most probably, webObj was obtained as a result of search by XPath and is a native DOM object.
HoverMouse() and Click() are methods provided by TestComplete and cannot be used for native DOM objects.
.click() (note small 'c') is a native method provided by DOM, so webObj.click() should work. I believe that something like webObj.hover() should exist in DOM as well.