I'm automating a webpage using JavaScript and selenium, which involves clicking on several buttons. To start off, my code establishes a connection with the existing chrome window in the following way:
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 is functioning correctly and navigates to the correct page. I've confirmed this by having the driver output the page's source code, which aligns with the site's source accessed through the right-click menu.
In addition, I have a function named checkForName(), which takes an XPath as input and 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 later invoked within the program
element = await checkForName("//button[@class='mBiMV']");
if(element) {
element.click();
}
However, upon running the program, the following error message appears in the console:
Checking for name
SnapBot-JS.js:18
Error: label //button[@class='mBiMV'] not found
I've double-checked the existence of the button, and the document is fully loaded before the chromedriver connects, leaving me uncertain about what steps to take next
EDIT: Below is the HTML code for the button in question:
<button type="button" class="mBiMV">