By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,761 Members | 1,009 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,761 IT Pros & Developers. It's quick & easy.

How to Press a Webpage Button with Python

P: 12
I would like to "press" a button on a webpage using a python script. When I say "press", I mean I would like to initiate all of the actions that would occur if you were to press the button with a mouse. Here is the html code for the button:

Expand|Select|Wrap|Line Numbers
  1.  <input type="button" 
  2. name="ctl00$MainPlaceHolder$submitOrder" 
  3. value="Submit Order >>" 
  4. onclick="this.disabled = true; this.value = 'Submitting Order...';__doPostBack('ctl00$MainPlaceHolder$submitOrder','')" 
  5. id="ctl00_MainPlaceHolder_submitOrder" 
  6. style="width:150px;font: bold 12px arial" />
Any help would be greatly appreciated.
Nov 10 '12 #1
Share this Question
Share on Google+
7 Replies

P: 12
There is a website (called investopedia) that allows you to conduct stock market trades without actually spending money. It is a stock simulator. Here is what I would like to do:
1. Log in to Investopedia
2. Make a trade (select 100 shares of APPL)
3. Execute the trade.
I can do the first 2 using mechanize or selenium. However, the third part messes me up. In order to execute the trade, you must press the "submit order button". When you press the submit order button, you are redirected to another page which tells you your order has been submitted. From what I gather, here is what happens when I press "submit order":
1. The order information is submitted to a server (or something like that).
2. The order is assigned an ID number.
3. Once the order has been submitted, a new url is created with the order ID in it, and you are sent to that url. (That would be the "your order has now been submitted" page).
How would I re-create this process with python? Please be specific; the html code for the button is above.
Nov 13 '12 #2

Expert Mod 5K+
P: 5,397
This is not a code writeing/do your project service.
You have your basic outline in #2 now you just need to research how it's done... more than likely a link into a dabase somehow...

Post your code and I'm sure that someone will be able to help you thru this.
Nov 14 '12 #3

P: 12

Oh. whoops! I'm new to bytes. I already have some code, I guess I'm just being a little lazy. I'll post the python code I already have shortly; thanks for letting me know.
Nov 14 '12 #4

Expert Mod 5K+
P: 5,397
Not an issue.
I figured you had the code to work with otherwise I would have closed your thread. Please remember to use the <CODE/> button to format your code when you post it.
Nov 14 '12 #5

P: 12
Ah, well. I figured it out on my own. But thanks for the help.
Nov 21 '12 #6

Expert Mod 5K+
P: 5,397
Would you please go ahead and post your solution so that others might benefit from it too - otherwise I should have simply deleted your thread to start with.
Nov 21 '12 #7

P: 12
I understand. Here is the code, for anyone who might find it helpful:

Expand|Select|Wrap|Line Numbers
  1. from selenium import webdriver
  2. from selenium.webdriver.common.keys import Keys
  4. #find the id of the button
  6. find_it = browser.find_element_by_id("ctl00_MainPlaceHolder_submitOrder")
  8. #"press" the enter key (with selenium)
  10. find_it.send_keys(Keys.RETURN)
  12. #the order should be submitted. 
Nov 21 '12 #8

Post your reply

Sign in to post your reply or Sign up for a free account.