Trying to locate an element with a structure similar to the following:
<div>
<div>
<div>
<ul>
<object id = "obj"
#document (link here)
<html>
<head> </head>
<body>
<div id = style4 >
I have attempted various methods to find this element, but it consistently results in a stale element exception. Here's what I've tried:
var table = wait.until(pkg.ExpectedConditions.presenceOfElementLocated(pkg.By.xpath('/html/body/div[8]/div/div/div[2]/div/div[2]/div/div/ul')));
WDS.browser.executeScript("arguments[0].scrollIntoView(true);", table);
WDS.log.info("Got Table");
// Find the <object> element within the table
var objectElement = table.findElement(pkg.By.tagName('object'));
WDS.log.info("Found objectElement");
// Extract the content of the <object> element
var objectContent = objectElement.getAttribute('data');
WDS.log.info("Extracted objectContent");
// Refresh the <object> element to prevent staleness
WDS.browser.executeScript("arguments[0].scrollIntoView(true);", objectElement);
WDS.log.info("Refreshed objectElement");
// Load the content document of the <object> element
var contentDocument = WDS.browser.executeScript("return arguments[0].contentDocument", objectElement);
WDS.log.info("Loaded contentDocument");
// Find the <html> element within the content document
var htmlElement = contentDocument.querySelector('html');
WDS.log.info("Found htmlElement: " + htmlElement);
This is the accompanying log:
2024-02-21 22:42:12,278 INFO c.g.j.p.w.s.WebDriverSampler: Got Table
2024-02-21 22:42:12,289 INFO c.g.j.p.w.s.WebDriverSampler: Found objectElement
2024-02-21 22:42:12,304 INFO c.g.j.p.w.s.WebDriverSampler: Extracted objectContent
2024-02-21 22:42:12,309 INFO c.g.j.p.w.s.WebDriverSampler: Refreshed objectElement
2024-02-21 22:42:12,317 ERROR c.g.j.p.w.s.WebDriverSampler: Error: org.openqa.selenium.StaleElementReferenceException: stale element reference: stale element not found
(Session info: chrome=122.0.6261.58)