I am encountering an issue while trying to access an element within a shadow iframe. I am able to switch to the frame successfully, but when attempting to access elements inside it, I am getting a Stale Element Exception. Any assistance with this would be greatly appreciated. Thank you in advance.
This is the code snippet I have been using:
public void enterCustomerDetails() throws InterruptedException {
Thread.sleep(2000);
WebElement root1 = sfdcSelFW.driver.findElement(By.tagName("sb-page-container"));
WebElement shadowRoot1 = expandRootElement(root1);
WebElement root2 = shadowRoot1.findElement(By.cssSelector("sb-line-editor"));
WebElement shadowRoot2 = expandRootElement(root2);
WebElement root3 = shadowRoot2.findElement(By.cssSelector("sb-le-custom-action-services"));
System.out.println(root3.getAttribute("id"));
WebElement shadowRoot3 = expandRootElement(root3);
WebElement root4 = shadowRoot3.findElement(By.cssSelector("span>sb-popup#popup"));
WebElement shadowRoot4 = expandRootElement(root4);
WebElement root5 = shadowRoot4.findElement(By.cssSelector("sb-dialog"));
WebElement shadowRoot5 = expandRootElement(root5);
sfdcSelFW.driver.switchTo().frame(shadowRoot5.findElement(By.cssSelector("div>div.sbDialog>div#content>iframe")));
Thread.sleep(10000);
WebElement saveBtnEle = shadowRoot5.findElement(By.cssSelector(" div.slds-grid input"));
saveBtnEle.click();
}
While executing the step "WebElement saveBtnEle = shadowRoot5.findElement(By.cssSelector(" div.slds-grid input"))" after switching to the frame, I am receiving the following exception:
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
(Session info: chrome=60.0.3112.101)
(Driver info: chromedriver=2.28.455520 (cc17746adff54984afff480136733114c6b3704b),platform=Windows NT 6.1.7601 SP1 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 92 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'AKKSR01-7470', ip: '10.135.116.222', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_144'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities [{applicationCacheEnabled=false, rotatable=false, mobileEmulationEnabled=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.28.455520 (cc17746adff54984afff480136733114c6b3704b), userDataDir=C:\Users\AKKSR01\AppData\Local\Temp\scoped_dir9256_23445}, takesHeapScreenshot for me...
Here is a sample snippet of the application and the DOM structure for reference