I am able to locate elements other than svg using either JS Path OR by using the plugin created by sukgu (https://github.com/sukgu/shadow-automation-selenium)
The problem is with svg element present inside the Shadow root, I am not able to locate it. Tried below methods:
While trying css selector to find the svg element, got below error:-
WebElement ele = (WebElement) js.executeScript("return document.querySelector(\"body > sn-component-va-web-client\").shadowRoot.querySelector(\"#Path\")"); ele.click();
Output -
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element
Using above mentioned plugin to find the svg - Using css selector
WebElement close = shadow.findElement("div > div.sn-cs-header > div.header-menu > div.menu-item.new-conversation-clicker > div.new-conversation-button > div > svg"); close.click();
Output -
org.openqa.selenium.ElementNotVisibleException: Element with CSS div > div.sn-cs-header > div.header-menu > div.menu-item.new-conversation-clicker > div.new-conversation-button > div > svg is not present on screen
Using Xpath
WebElement close = shadow.findElementByXPath("//*[local-name()='svg']//g//g//g//path[@id='Path']"); close.click();
Output -
org.openqa.selenium.ElementNotVisibleException: Element with XPath //*[local-name()='svg']//g//g//g//path[@id='Path'] is not present on screen
Below is the HTML :-
<div class="conversation-container" style="display: block;">
<iframe title="Chat Support" id="myiFrame" class="chat-frame" scrolling="no" horizontalscrolling="no" verticalscrolling="no" frameborder="none" ng-src="/$sn-va-web-client-app.do?sysparm_nostack=true&sysparm_stack=no" src="/$sn-va-web-client-app.do?sysparm_nostack=true&sysparm_stack=no"></iframe>
</div>
<iframe title="Chat Support" id="myiFrame" class="chat-frame" scrolling="no" horizontalscrolling="no" verticalscrolling="no" frameborder="none" ng-src="/$sn-va-web-client-app.do?sysparm_nostack=true&sysparm_stack=no" src="/$sn-va-web-client-app.do?sysparm_nostack=true&sysparm_stack=no"></iframe>
#document
<html>
<head>
<body>
<sn-component-va-web-client component-id="cid1" now-id="cid1"></sn-component-va-web-client>
#shadow-root (open)
<div class="sn-cs-webclient fill-window text-direction-ltr">
<div class="sn-cs-accessibility-reader" aria-live="polite" aria-atomic="false"></div>
<div></div>
<div class="sn-cs-header" style="z-index: 500;">
<div class="chat-title">
<div class="header-circle">
<img class="header-icon " src="599c06dedbbe6c109005db184b961967.iix" alt="Header Icon">
</div>
</div>
<div class="header-menu">
<div class="menu-item new-conversation-clicker " aria-label="End conversation" aria-haspopup="menu" role="button" aria-describedby="new-conversation-tip" tabindex="0">
<div class="new-conversation-button">
<div class="new-convo-icon close-icon">
<svg viewBox="0 0 26 23" version="1.1"
xmlns="http://www.w3.org/2000/svg">
<g id="Symbols" stroke="none" stroke-width="1" fill="rgba(0,0,0,0)" fill-rule="evenodd">
<g id="header/New-header-la-no-name" transform="translate(-330.000000, -20.000000)" fill-rule="nonzero" stroke="#ffffff" stroke-width="2">
<g id="Group" transform="translate(329.000000, 20.000000)">
<path d="M13.55,1 C7.17042969,1
<!-- removed extra numbers --> 19.9295703,1 13.55,1 Z" id="Path">
</path>
</g>
</g>
</g>
</svg>