I am facing an issue while using Selenium to capture text injected by a Chrome Extension. Even though the text is being injected correctly, I am struggling to make the Selenium test wait for the div to appear and then store the inner text in a variable. Can anyone help me figure out what I might be missing?
When I check the console.log, it shows "Promise { < pending> }"
Here are the snippets:
Content Script of Chrome Extension-
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
var para = document.createElement("p");
para.id = "selenium-container";
var node = document.createTextNode(request.queryParameters);
para.appendChild(node);
window.document.body.appendChild(para);
});
Selenium Test Script -
async function Test() {
let driver = builder
.forBrowser('chrome')
.withCapabilities({
'browserName': 'chrome',
'chromeOptions':
{
binary: '...',
args: [],
extensions: ['...']
}
})
.setChromeOptions(options)
.build();
// Tests
await driver.get('URL-HERE');
const seleniumContainerElement = By.id("selenium-container");
await driver.wait(until.elementLocated(seleniumContainerElement, 10000))
.then( (seleniumContainerElement) => {
console.log(seleniumContainerElement.getAttribute('innerHTML'));
});
...