Physically moving the mouse

hi everyone,

I’m just trying this software and bumped into an issue already.

Created a Test Case which navigates to, clicks around a little in ‘Pricing’ and that’s it.

However, there’s this “Need help choosing the right plan?” message that pops up when physically moving the mouse, but otherwise it doesn’t.
(The HTML is


Now… I couldn’t find a way to simulate this and make the pop up come up so my script can close it. In other words, my script fails with an error, as when I recorded the events, I actually moved the mouse and had to close this window, but in automation, it doesn’t come.
I COULD remove this line to make the script work, but I want to test if the popup comes on mouse move and I can close it (why not? :slight_smile: ).

Again, it’s not “Mouse Over”, I tried that and it doesn’t work.

So, is there a way to make this happen? Move the mouse so the popup appears, so I can close it?


p.s. Bonus question :slight_smile: How about OS-indicated pop ups that block the browser, like security or permission pop ups / notifications?

Okay, you tried mouseOver(), but then did you explore the HTML of the components that arise when you do that. Manually, put your mouse over the target when the popup shows, then right click on the popup and select Inspect (you might have to do this twice to have the HTML move directly to your element). Check if there is now some HTML there that you can interact with.

Maybe like:
"hover over graphic icon"

WebUI.delay(1)     // increase this to 5 as one of your tests

'to locate pop-up table'
WebElement Table2 = DriverFactory.getWebDriver().findElement(By.xpath("//table[@class='table table-info-popover']/tbody"));

blah blah blah

In my case, the contents was like a web table, however, in another instance, there were a list of items that I could treat as WebElements. Both of these concepts are explained and searchable within the KS forum. See if that gives you something, then update this chain and see if we can help after that.

Ergh. Okay. So you say, the event is not triggered by some JS “code”, reacting to the mouse move, but it it tied to an onscreen object? Because IMO it’s the prior thing.
Plus, my manual guys won’t be able to do this.

So… Plan “B”. Is there a way to add C++ or C# code as an “action” in there? I can move the mouse physically from C++, so all I need is being able to call that code from the Codeless UI (and can share with manual testers to click it together, like inject an action.



So… Plan “B”. Is there a way to add Java or Groovy code as an “action” in there? Yes.
(it shouldn’t be too hard for you to alter your C# code to find the Java or Groovy equivalent.)

For future generations to come:

package customActions
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.checkpoint.Checkpoint
import com.kms.katalon.core.checkpoint.CheckpointFactory
import com.kms.katalon.core.model.FailureHandling
import com.kms.katalon.core.testcase.TestCase
import com.kms.katalon.core.testcase.TestCaseFactory
import com.kms.katalon.core.testdata.TestData
import com.kms.katalon.core.testdata.TestDataFactory
import com.kms.katalon.core.testobject.ObjectRepository
import com.kms.katalon.core.testobject.TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords

import internal.GlobalVariable

import org.openqa.selenium.WebElement
import org.openqa.selenium.WebDriver
import org.openqa.selenium.By

import com.kms.katalon.core.webui.driver.DriverFactory

import com.kms.katalon.core.testobject.RequestObject
import com.kms.katalon.core.testobject.ResponseObject
import com.kms.katalon.core.testobject.ConditionType
import com.kms.katalon.core.testobject.TestObjectProperty

import com.kms.katalon.core.util.KeywordUtil

import com.kms.katalon.core.webui.exception.WebElementNotFoundException
import java.awt.Robot;
import java.awt.Point;
import java.awt.MouseInfo;
import java.util.concurrent.ThreadLocalRandom;
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI;

class MouseActions {

	 * Move the mouse to point X, Y within the browser. Set negative value(s) for a random position
	@Keyword (keywordObject = "Browser")
	def MoveMouse(int X, int Y, long speed, int mrate) {
		KeywordUtil.logInfo("MoveMouse() called, initializing");
		long moveSpeed = speed;
		if (moveSpeed < 0) { moveSpeed = 7; }
		int newX = X;
		int newY = Y;
		int bWidth = WebUI.getViewportWidth();
		int bHeight = WebUI.getViewportHeight();
		if ((bWidth < newX) || (bHeight < newY)) {
			KeywordUtil.markFailedAndStop("X and Y coordinates are outside the window's boundaries");
		if ((newX < 0) || (newY < 0)) { //random it is
			//let's assume we won't roll the very same location where the mouse is atm
			newX = ThreadLocalRandom.current().nextInt(0, bWidth  - 1);
			newY = ThreadLocalRandom.current().nextInt(0, bHeight - 1);
		Robot rb = new Robot();
		Point newP = new Point(newX, newY);
		Point mpos = MouseInfo.getPointerInfo().getLocation();
		int moveRate = mrate;
		if (moveRate < 1) { moveRate = 25; }
		int moveByX = ((mpos.x - newX) / moveRate) * -1;
		int moveByY = ((mpos.y - newY) / moveRate) * -1;

		KeywordUtil.logInfo("Moving the mouse");
		while (moveRate > 0) {
			mpos = MouseInfo.getPointerInfo().getLocation();
			rb.mouseMove((int)(mpos.getX() + moveByX), (int)(mpos.getY() + moveByY));
			if (moveSpeed > 0) { Thread.sleep(moveSpeed); }
		KeywordUtil.markPassed("Moving the mouse completed!");
1 Like