0

Hello I want to try to run all of these code on console chrome

var xxx = document.querySelectorAll('.balanceDetails-manageCurrencies.test_mcm-addCurrency')
xxx.forEach(btn => btn.click())
var twd = document.querySelectorAll('.shadow.multiCurrency-flag.multiCurrency-flag_TWD')
twd.forEach(btn => btn.click())
var addcurrency = document.querySelectorAll('.btn.vx_btn.mandate_lg-btn.test_mcm-addCurrencyButton')
addcurrency.forEach(btn => btn.click())

But it doesnt run everything, the process just stop when they excute line number 2

xxx.forEach(btn => btn.click())

Question is, how to run all of these code?

  • Have you checked out this documentation page yet? https://developers.google.com/web/tools/chrome-devtools/console/utilities – Sterling Archer Feb 21 '20 at 14:04
  • well does the button refresh the page or submit a form? My guess is the click does something and stops the code – epascarello Feb 21 '20 at 14:08
  • @epascarello yesss! right, they refresh to submit form – Hacking to Win Feb 21 '20 at 14:13
  • @epascarello do you know how to handle this? – Hacking to Win Feb 21 '20 at 14:14
  • Well it is not going to happen in the console. You are really using the wrong tool if you want to automate something. You want to look into Selenium. – epascarello Feb 21 '20 at 14:15
  • @epascarello So the console is can't use this one? Yes i want to do automate something on form. So what should I use? Except imacros or UI.vison (Kantu) – Hacking to Win Feb 21 '20 at 14:17
  • Problem is with console, it is just like code being on the page. So when the page exits, so does the console. I would use https://chrome.google.com/webstore/detail/selenium-ide/mooikfkahbdckldjjndioackbalphokd or Selenium WebDriver – epascarello Feb 21 '20 at 14:19

2 Answers2

0

Try combining the arrays then running the click loop on the new array.

replace sel1 etc to your selectors

var xxx = [...document.querySelectorAll(sel1), ...document.querySelectorAll(sel2), ...document.querySelectorAll(sel3)]
xxx.forEach(el => el.click())
Gene Sy
  • 1,325
  • 2
  • 10
  • 17
  • Seems its work, but again it just run the first array. Because the PAGE is need to load array 1 to next step on array 2. Hope you understand what i mean – Hacking to Win Feb 21 '20 at 14:09
  • Are you sure the elements in sel2 are visible/clickable? – Gene Sy Feb 21 '20 at 14:10
  • No, when I run the array 1 they load new website / load another html code. But the website is same. They just redirect to a LIST of CURRENCIES and Array 2 is SELECT the CURRENCIES, Array 3 is CONFIRM – Hacking to Win Feb 21 '20 at 14:13
  • Then you'll need to run your original commands but add a setTImeout before the next lines to make sure the next elements are there and ready to be clicked – Gene Sy Feb 21 '20 at 14:31
  • And what the code i had to use to add setTimeout? I put that after the first one action right? – Hacking to Win Feb 21 '20 at 14:34
  • Yes, thank's its worked! I just need to add this console.log(setTimeout(() => console.log('a'), 3000)); And then the second and third function will run without error. Thanks – Hacking to Win Feb 21 '20 at 14:37
0

It's hard to tell what's going on in your case because we don't know what your selected DOM nodes are doing after being clicked. If you paste that entire code block into the chrome console I would expect it to execute all of it.

Two things off the top of my head could be happening.

  1. The click handler setup to fire on one of those DOM nodes is throwing an error, but that error is being caught by a try/catch block and never bubbles up to the console. This would create the symptoms described.

  2. The click handler for one of those DOM nodes is doing a form post, or something else that will cause the page to reload. Although, if this were the case you'd see the console clear. Not sure if you're seeing that or not.

Jesse Lee
  • 1,291
  • 1
  • 8
  • 20
  • What i selected is The First one Add a New currencies on Paypal, The Second one Is Selected Spesific Currencies, The Third one is Confirm Yes when i do the first one, they reload a new AJAX or something like LIST of the currencies, and yes they redirect to another page but it AJAX. I just had to selected which currencies i want. – Hacking to Win Feb 21 '20 at 14:28