I'm using JavaScript with selenium to automate a webpage that has several buttons I need to click on. My code starts by connecting to the existing chrome window as shown:
var chrome = require("selenium-webdriver/chrome");
var options = new chrome.Options();
options.options_["debuggerAddress"] = "127.0.0.1:9222";
var driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();
The driver works successfully and has the correct page, I have verified this by having the driver print the source code of the page, which matches with the page source of the site from the right-click menu.
I also have a function called checkForName(), which, given an XPath, returns the element for selenium to interact with
async function checkForName(selector) {
console.log("Checking for name");
try {
const element = await driver.findElement(By.xpath(selector));
return element;
} finally {
console.log("Error: element " + selector + " not found");
return false;
}
}
This function is then called later on in the program
element = await checkForName("//button[@class='mBiMV']");
if(element) {
element.click();
}
However, when the program is run, this error pops up in the console:
Checking for name
SnapBot-JS.js:18
Error: label //button[@class='mBiMV'] not found
I've verified that the button exists, and the document is fully loaded before the chromedriver connects, so I'm not sure what to do at this point
EDIT: Here's the HTML code of the button in question:
<button type="button" class="mBiMV">