0

I am passing input to rich text field. For that I have written the code below:

public void inputToDescriptionField() throws InterruptedException   , AWTException
{
    
    wait.until(ExpectedConditions.elementToBeClickable(descriptionField));
    Actions a = new Actions(driver);
    a.moveToElement(descriptionField).click().build().perform();        

    Robot r = new Robot();
    String text = "Program Description";
    StringSelection stringSelection = new StringSelection(text);
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
     clipboard.setContents(stringSelection, stringSelection);
        
       r.keyPress(KeyEvent.VK_CONTROL);
       r.keyPress(KeyEvent.VK_V);
       r.keyRelease(KeyEvent.VK_V);
       r.keyRelease(KeyEvent.VK_CONTROL);

but I am getting the error move target out of bounds

1
  • Could you please edit your question to include the HTML of the rich text field? The target out of bounds error suggests that there could be an issue with the element's availability.
    – Kate Paulk
    Mar 8 at 13:11

1 Answer 1

0

The error message:

"org.openqa.selenium.interactions.
MoveTargetOutOfBoundsException: 
move target out of bounds" 

typically occurs when the target element is not visible or outside the visible area of the screen. Here are some possible solutions to try:

1 Scroll to the element: If the element is not visible, you can try scrolling to it using the scrollIntoView method. For example:

JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].scrollIntoView(true);", descriptionField);

2 Use an offset: If the element is partially hidden or overlapped by another element, you can try using an offset to move the mouse pointer slightly away from the center of the element. For example:

Actions a = new Actions(driver);
a.moveToElement(descriptionField, 5, 5).click().build().perform();

3 Use a different approach: Instead of using Actions and Robot to simulate typing, you can try using the sendKeys method to directly send the text to the element. For example:

descriptionField.sendKeys("Program Description");

4 Check if the element is present: Before performing any actions on the element, you can check if the element is present in the DOM using ExpectedConditions.presenceOfElementLocated. For example:

wait.until(ExpectedConditions.presenceOfElementLocated(By.id("descriptionField")));

It's also possible that the error is caused by a bug in Selenium or the browser driver. In that case, you can try updating to the latest version of Selenium and the browser driver, or using a different browser or driver.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.