0

I am new to JavaScript! I'm trying to make a program with Virtual Studio that automatically buys things for me on ROBLOX, it's all working but I can't find a way to get the script to click the Buy with Tx element on this page! I've tried:

Form2.WebBrowser1.Document
     .GetElementById("ctl00_cphRoblox_TicketsPurchasePanel").InvokeMember("click")

and:

Form2.WebBrowser1.Document
     .GetElementById("BuyWithTickets").InvokeMember("click")

The second one seems like it should work as the button has the ID BuyWithTickets. I don't understand why and as I said, I am new to JavaScript and this is one of my first projects.

My problem is not that I don't know how to simulate a click, it's that I have no idea how to get the element id of this button I want clicked!

aaron
  • 21
  • 1
  • 3

2 Answers2

0

The first ID "ctl00_cphRoblox_TicketsPurchasePanel" is the surrounding div (see highlighted below). The second one is also a surrounding div. Both of these are used for layout around the button. The button is the one that is in the centre (in blue below) and will be the only one that handles a click event.

enter image description here

This doesn't have an ID on it so you're going to have to target by a combination of ID and class, e.g. in JavaScript this would be...

document.querySelector("#BuyWithTickets .PurchaseButton")

or use .GetElementById("BuyWithTickets") and then find the first child div and invoke click on that.

You can inspect elements in Chrome (right click on the element and choose Inspect) then look at Event Listeners on the right (I've unticked Ancestors and Framework Listeners) to see which elements have events on them like click events.

enter image description here

Quantumplate
  • 1,104
  • 8
  • 15
  • I've probably done something completely wrong, I changed my code to: `Form2.WebBrowser1.Document.GetElementById("ctl00_cphRoblox_TicketsPurchasePanel")#BuyWithTickets.PurchaseButton.InvokeMember("click")` It now just doesn't work at all, I probably need a bit more explanation if possible. – aaron Dec 26 '15 at 21:33
  • Sorry, that text above is a CSS selector to give you an example that you need to target the child element (and possibly by class). I don't know the exact syntax but it may be something like `Form2.WebBrowser1.Document .GetElementById("BuyWithTickets").Children[0].InvokeMember("click")` – Quantumplate Dec 26 '15 at 21:45
  • @aaron I've changed my example from CSS one to JavaScript one using querySelector(). This may be more useful to you. You can copy and paste this into Console tab in Chrome dev tools to see it work. – Quantumplate Dec 26 '15 at 22:04
  • I get these 2 errors: Identifier expected and Property access must assign to the property or use its value. I don't completely know what these mean. I had no errors before I changed it to this, I then changed .Children[0] too ,FirstChild and it didn't error, it just didn't work. – aaron Dec 27 '15 at 09:24
  • Here's a snippet of my code: http://prntscr.com/9izzcm < Hopefully that will help! – aaron Dec 27 '15 at 10:36
  • Would it be easier to simulate the click on the Tickets button on this page: https://m.roblox.com/items/316532787 – aaron Dec 27 '15 at 11:07
0

check this out, it has been taken from the mozilla developer network, where you can find solid information about javascript, and more technologies, in this test you add a event listener function with a “callback” what is called when you do an event (click) in the selected element (“test”) and the function in braces is called.

PD: If you’re new i suggest you to later check the jQuery plugin for javascript.

<html>

<body>
  <div id='test'>Click me!</div>
  <script>
    document.getElementById('test').addEventListener("click", function() {
      // display the current click count inside the clicked div
      document.getElementById('test').innerHTML = "You clicked me!"
    });
  </script>
</body>

</html>
cesargdm
  • 95
  • 1
  • 9