0

I want to double click on an element hence have following code -

Actions builder=new Actions(driver);
builder.doubleClick(visibleElement).perform();

But for double click, it results into -

org.openqa.selenium.WebDriverException: unknown error: failed to parse value of getElementRegion

I googled it a lot but did not get what is cause of this and how to resolve this. Could you please help with this?

Alpha
  • 13,320
  • 27
  • 96
  • 163
  • Don’t know your use case.However if you click twice on the element it doesn’t work? – KunduK Jan 06 '20 at 11:30
  • Try this one `builder.moveToElement(visibleElement).doubleClick(visibleElement).build().perform();` – KunduK Jan 06 '20 at 11:35

1 Answers1

0

This error message...

org.openqa.selenium.WebDriverException: unknown error: failed to parse value of getElementRegion

...implies that the GetElementRegion() method failed to parse the value.


Deep dive

This error is coming from element_util.cc:

Status GetElementRegion(
    Session* session,
    WebView* web_view,
    const std::string& element_id,
    WebRect* rect) {
  Status status = CheckElement(element_id);
  if (status.IsError())
    return status;
  base::ListValue args;
  args.Append(CreateElement(element_id));
  std::unique_ptr<base::Value> result;
  status = web_view->CallFunction(
      session->GetCurrentFrameId(), kGetElementRegionScript, args, &result);
  if (status.IsError())
    return status;
  if (!ParseFromValue(result.get(), rect)) {
    return Status(kUnknownError,
          "failed to parse value of getElementRegion");
  }
  return Status(kOk);
}

Reasons and Solutions

There can be diverse reasons and solutions to this error as follows:

  • Ensure the Locator Strategy for visibleElement identifies the element uniquely within the DOM Tree
  • Induce WebDriverWait for the elementToBeClickable() before you invoke doubleClick() as follows:

    new Actions(driver).doubleClick(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(visibleElement))).perform();
    
  • Add the build() step:

    new Actions(driver).doubleClick(new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(visibleElement))).build().perform();
    
  • Before you try to invoke doubleClick() from Actions Class ensure that Selenium have the focus within the correct Frame i.e. either the Top Level View or an <iframe> element.

Here you can find a relevant discussion on Ways to deal with #document under iframe

Here you can find a relevant discussion on How to automate shadow DOM elements using selenium?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352