Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Commit 01fcd70

Browse files
committed
fix follow button xpath
mifi/SimpleInstaBot#106
1 parent 1adf00a commit 01fcd70

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

index.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,31 @@ const Instauto = async (db, browser, options) => {
242242
}
243243
}
244244

245-
async function findFollowButton() {
246-
const elementHandles = await page.$x("//header//button[text()='Follow']");
245+
// How to test xpaths in the browser:
246+
// document.evaluate("your xpath", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null ).singleNodeValue
247+
async function findButtonWithText(text) {
248+
// todo escape text?
249+
250+
// button seems to look like this now:
251+
// <button class="..."><div class="...">Follow</div></button>
252+
// https://sqa.stackexchange.com/questions/36918/xpath-text-buy-now-is-working-but-not-containstext-buy-now
253+
// https://github.com/mifi/SimpleInstaBot/issues/106
254+
let elementHandles = await page.$x(`//header//button[contains(.,'${text}')]`);
247255
if (elementHandles.length > 0) return elementHandles[0];
248256

249-
const elementHandles2 = await page.$x("//header//button[text()='Follow Back']");
250-
if (elementHandles2.length > 0) return elementHandles2[0];
257+
// old button:
258+
elementHandles = await page.$x(`//header//button[text()='${text}']`);
259+
if (elementHandles.length > 0) return elementHandles[0];
260+
261+
return undefined;
262+
}
263+
264+
async function findFollowButton() {
265+
let button = await findButtonWithText('Follow');
266+
if (button) return button;
267+
268+
button = await findButtonWithText('Follow Back');
269+
if (button) return button;
251270

252271
return undefined;
253272
}

0 commit comments

Comments
 (0)