instauto 7.2.0 → 7.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +23 -4
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -242,12 +242,31 @@ const Instauto = async (db, browser, options) => {
|
|
|
242
242
|
}
|
|
243
243
|
}
|
|
244
244
|
|
|
245
|
-
|
|
246
|
-
|
|
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}')]`);
|
|
247
255
|
if (elementHandles.length > 0) return elementHandles[0];
|
|
248
256
|
|
|
249
|
-
|
|
250
|
-
|
|
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;
|
|
251
270
|
|
|
252
271
|
return undefined;
|
|
253
272
|
}
|