-1

So, I'll start off by showing you the current code

var CurrItem = document.querySelector('input[value="Insane 4"]').click();
SetTimeout(function(){CurrItem.Click();,10000}

This is what it looks like, I assumed it would select a input text of "Insane 4.." and then click it.

Now what it actually did was absolutely nothing.

I'm trying to click the object by input so I can automate a sell system to select a Object named "Insane #" then click another button with the input of "Sell"

This is what I'm trying to click within the browser

This is the code for the above

Things to keep in mind:

RowID Always changes.

I'm going to be doing more then "4" (4 - 11)

I'm using TamperMonkey to run the script.

James B
  • 33
  • 6
  • Where in that screenshot do you see an `input` element? – Sam Hanley Jan 09 '16 at 19:38
  • Can't you assign an ID to the element at creation? Also, input[value=someValue] searches for input elements () with value = someValue. For some guidance see http://stackoverflow.com/questions/2694640/find-an-element-in-dom-based-on-an-attribute-value/16775485#16775485 – Ignacy Debicki Jan 09 '16 at 19:40
  • Whoops. grabbed it from another script of mine i thought the input was the actual Text Value within it, how would I select it? – James B Jan 09 '16 at 19:40
  • Can you show more of the page/html? It looks like the 'a' tag in your html handles the click so you want to simulate a click on this. Unless you can select by RowID you may need to return all rows and search inner html for your text 'Insane 4'. – Quantumplate Jan 09 '16 at 19:56
  • Would it be possible to do something along these lines var CurrItem = document.querySelectorAll(document.GetElementByID('b').innerhtml("Insane 4")); – James B Jan 09 '16 at 20:05
  • the b has the actual innerhtml i would need to look at specifically – James B Jan 09 '16 at 20:06

1 Answers1

0

A suggestion: learn some fundamentals of programming before writing any code, specifically about method and method calls.

In Javascript, function is a first class object, quoting from wiki:

In computer science, a programming language is said to support first-class functions (or function literal) if it treats functions as first-class objects. Specifically, this means that the language supports constructing new functions during the execution of a program, storing them in data structures, passing them as arguments to other functions, and returning them as the values of other functions.

setTimeout accepts function as its first parameter: https://developer.mozilla.org/en-US/docs/Web/API/WindowTimers/setTimeout

var timeoutID = window.setTimeout(code, [delay]);

Therefore, you need to declare a function that calls .click() and then pass it to setTimeout. I won't directly fix your code, but will give you a general syntax to get you started:

var doClick = function() {
  //Your code to .click() here
}

setTimeout(doClick, 10000);
Andreas Wong
  • 59,630
  • 19
  • 106
  • 123