4

I have a website built with Polymer 2 with a DOM structure that looks like:

...
<df-link slot="local-nav-drawer-link" link-href="/dictionary" text-color="light">
    #shadow-root (open)
    <a href="/dictionary" title="">
        <dom-if style="display: none;">
            <template is="dom-if"></template>
        </dom-if>
        <span class="dfpl-link__text">Dictionary</span>
    </a>
</df-link>
...

Using the page object pattern which defines the shadow root and the element I want to click as:

@FindBy(css = "df-link")
public WebElement shadowRootElement;

public By shadowAnchorElementSelector = By.cssSelector("a");

The code to retrieve the shadow root element looks like:

WebElement shadowRoot;
shadowRoot = (WebElement) jsExec.executeScript("return arguments[0].shadowRoot;", shadowRootElement);
WebElement anchor = shadowRoot.findElement(shadowAnchorElementSelector);
anchor.click();

I can successfully get attribute values, css values, and the inner text. However when I call a click this is what happens.

Apr 18, 2018 10:25:28 AM org.openqa.selenium.remote.server.WebDriverServlet handle
INFO: Found handler: org.openqa.selenium.remote.server.ServicedSession@136d9af5
Apr 18, 2018 10:25:28 AM org.openqa.selenium.remote.server.WebDriverServlet lambda$handle$0
INFO: Handler thread for session 2525b788dd3471e51e986fed682f04ea (chrome): 
Executing POST on /session/2525b788dd3471e51e986fed682f04ea/element/0.23700467091154298-6/click (handler: ServicedSession)
Apr 18, 2018 10:25:28 AM org.openqa.selenium.remote.server.Passthrough handle
INFO: To upstream: {"id":"0.23700467091154298-6"}
Apr 18, 2018 10:25:28 AM org.openqa.selenium.remote.server.Passthrough handle
INFO: To downstream: {"sessionId":"2525b788dd3471e51e986fed682f04ea","status":13,"value":{"message":"unknown error: Cannot read property 'defaultView' of undefined\n  (Session info: chrome=66.0.3359.117)\n  (Driver info: chromedriver=2.38.551601 (edb21f07fc70e9027c746edd3201443e011a61ed),platform=Windows NT 10.0.16299 x86_64)"}}

It looks as though the element is found fine, and I read from it, but as soon as I call WebElement.click() the error "Cannot read property 'defaultView' of undefined" is returned from ChromeDriver. I have not seen this posted around, and I am really stuck, wondering if someone has an answer for this.

This is with Chrome 66 and ChromeDriver 2.38.

  • Guessing here... Have you tried going down to the span and using click on it? Have you tried using 2.37 which also supports chrome 66. – Grasshopper Apr 18 '18 at 18:26
  • @Grasshopper I have tried clicking the span with the same result. And I started with 2.37 with the same result as well.I have tried 2.37 with Chrome 65 and 66, and 2.38 with Chrome 66. – Nikolas Harris Apr 18 '18 at 18:35

2 Answers2

1

I just had this issue and was able to fix it by using firefox and geckodriver instead of chrome driver. Fixed everything.

Ethan King
  • 19
  • 2
0

Try with the below code

   public void forceClickElement(WebElement element){

        jsExec.executeScript("arguments[0].click();", element);
    }
Ashok kumar Ganesan
  • 1,098
  • 5
  • 20
  • 48
bbb
  • 11