'Selenium - is there a way to move the mouse off page without getting the 'move target out of bounds' error?
My test requires the mouse to go off page and come back to the field. I am using Selenium and the test is run from Jenkins on Browserstack. In Browserstack, the text is keyed in User ID field and then the test stops. The error message captured is move target out of bounds.
Could you please help me find a way so I can move the mouse off page and come back and then proceed with the next steps.
browserStackDriver.manage().window().maximize();
//chrome 47 need more move to trigger mouse_off.
int adjustYOffset = (browser.toLowerCase().contains("chrome") && Integer.valueOf(browser.substring(7, 7 + 2)) <= 47) ? 20 : 0;
Action mouseOffUserid =
builder.moveToElement(userid).click().sendKeys(userid, "senkeytestOFFPAGE").moveByOffset(0, -1 * (120 + adjustYOffset)).moveByOffset(0, 120 + adjustYOffset).build();
Action mouseOffPsw =
builder.moveToElement(psw).click().sendKeys(psw, "senkeytestOFFPAGE").moveByOffset(0, -1 * (150 + adjustYOffset)).moveByOffset(0, 150 + adjustYOffset).build();
Action mouseClickUserid = builder.moveToElement(userid).click().sendKeys(userid, "senkeytest").build();
//going off page from userid
mouseOffUserid.perform();
QueryManager.giveDelay(1000);
//going off page from psw
mouseOffPsw.perform();
QueryManager.giveDelay(1000);
Edit : Tried several other options to achieve the same i.e., get the mouse off page, off the viewport and then come back to the page. Tried with Robot class as well, but did not help. Using the below code, which is more of less similar to what was done before, the mouse off page works for Chrome 90 and below version. All versions above Chrome 90, Safari this is not working. Please help.
public void moveOffpage(String os, String browser) {
browserStackDriver.manage().window().maximize();
userid.sendKeys("text 1");
Actions builder = new Actions(browserStackDriver);
builder.keyDown(Keys.CONTROL)
.clickAndHold(userid)
.moveByOffset( 0, -140 )
.build().perform();
userid.sendKeys("text 2");
psw.sendKeys("Text 3");
builder.keyDown(Keys.CONTROL)
.clickAndHold(psw)
.moveByOffset( 0, -180 )
.build().perform();
psw.sendKeys("Text 4");
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
