I’m trying to make a program where if I give it a web page and any word it will click that for example I can give it a Github profile and give the word “Follow” then it will press that follow button, and start following that Github profile.
How can I do this in Selenium? I’m currently getting this error: Error occurred: ElementClickInterceptedError: element click intercepted:
Code:
import { Builder, By, until } from "selenium-webdriver";
async function clickElementWithText(url, targetText) {
const driver = await new Builder().forBrowser("chrome").build();
try {
await driver.get(url);
const element = await driver.wait(
until.elementLocated(
By.xpath(`//body//text()[contains(., '${targetText}')]/parent::*`)
),
10000
);
await element.click();
console.log(`Clicked on element containing "${targetText}"`);
} catch (error) {
console.error("Error occurred:", error);
}
}
const url = "https://github.com/shs96c";
const targetText = "Follow";
clickElementWithText(url, targetText);