473,320 Members | 1,936 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to Press a Webpage Button with Python

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" />
  7.  
Any help would be greatly appreciated.
Nov 10 '12 #1
7 6339
kttr
12
EDIT:
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
zmbd
5,501 Expert Mod 4TB
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
kttr
12
@zmbd

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
zmbd
5,501 Expert Mod 4TB
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
kttr
12
@zmbd
Ah, well. I figured it out on my own. But thanks for the help.
Nov 21 '12 #6
zmbd
5,501 Expert Mod 4TB
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
kttr
12
@zmbd
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
  3.  
  4. #find the id of the button
  5.  
  6. find_it = browser.find_element_by_id("ctl00_MainPlaceHolder_submitOrder")
  7.  
  8. #"press" the enter key (with selenium)
  9.  
  10. find_it.send_keys(Keys.RETURN)
  11.  
  12. #the order should be submitted. 
  13.  
Nov 21 '12 #8

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

Similar topics

12
by: Elliot Temple | last post by:
How do I make Python press a button on a webpage? I looked at urllib, but I only see how to open a URL with that. I searched google but no luck. For example, google has a button <input...
15
by: qwweeeit | last post by:
Hi all, Elliot Temple on the 1 June wrote: > How do I make Python press a button on a webpage? I looked at > urllib, but I only see how to open a URL with that. I searched > google but no...
0
by: Rainer Halanek | last post by:
Hi, I want to write an asp.net application, that fills out automatically some fields on a webpage (public one, not asp.net), press there a submit button and do some more stuff (like filling out...
0
by: Preethi | last post by:
Hi Dudes, I have an issue while developing Asp.Net application, The issue is If i Press Back Button on the Menu, the page should not go to theprevious page. In order to Restrict it what I...
2
Atran
by: Atran | last post by:
Hello: I have two programs (Windows Forms). I want to make the second program runs when I press a button in the first program. So when the user go to run the second program, I want the second...
4
neo008
by: neo008 | last post by:
Hi All, Can I prevent user to press cross button? I want to disable all three buttons for minimize, maximize and close for parent as well as child window. Is it possible? I'm using VB6. ...
3
by: Shaileshsharma | last post by:
Hi, I want when my cursor is in textbox and i press tab button a message will display or when i press tab the text in text box should save in database.Kindly help me how it is possible. ...
0
by: srirampavan | last post by:
how to get login prompt window when we press radio button??/
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.