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.
Files changed (2) hide show
  1. package/index.js +23 -4
  2. 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
- 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}')]`);
247
255
  if (elementHandles.length > 0) return elementHandles[0];
248
256
 
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;
251
270
 
252
271
  return undefined;
253
272
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "instauto",
3
- "version": "7.2.0",
3
+ "version": "7.2.1",
4
4
  "description": "Instagram automation library written in Node.js",
5
5
  "main": "index.js",
6
6
  "scripts": {