Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-25-2008, 12:16 PM   PM User | #1
noamjob
New to the CF scene

 
Join Date: Dec 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
noamjob is an unknown quantity at this point
How to click a button programatically?

Here is what I need to do:

Let's say I want to make a program that perform a search by First Name in a site like this(only for demonstration, I'm not spamming...):

http://www.draftexpress.com/search.php



Let's say I want to search for "james".



How do I do it? I spent many hours on this and couldn't find out...

The main problem iis that the website is not mine, so how can I access its components?(Let's say I want to "click" the search button there programatically)?

Is there a way to do it?

I would appreciate if you expain in details, I'm preety much new in that area...



thanks,

Noam
noamjob is offline   Reply With Quote
Old 12-26-2008, 01:12 AM   PM User | #2
itsallkizza
Senior Coder

 
Join Date: Oct 2008
Location: Long Beach
Posts: 1,196
Thanks: 36
Thanked 164 Times in 164 Posts
itsallkizza will become famous soon enough
First, look to see if they have an API released for public use. If they don't, then snoop around to see if they use GET instead of POST (like Google) in which case you can simulate an API.

If they are using POST for their searches, have not released an API for public use, and if their search is using any domain sandboxed code (eg any sort of ajax or server-side database calls), which it almost definitely is, then you're out of luck.

I checked out the link your posted and their search form is indeed POSTing the user's input to http://www.draftexpress.com/search.php#results so chances are you're not going to be able to do what you want using web-specific scripts. However, in principle, anything you can do manually on a computer you can also simulate. If this project is important to you, then get your hands dirty in some C/C++. There are ways to simulate browser focus and mouse/keyboard commands (in order to fill in the forms and submit) and there are plenty of screen-scraper programs out there too (to grab the data once you've got the results on screen).

However, you might try sniffing around their site to make sure they don't have an API for ya, or e-mail someone who works there and ask them if they might have what you want.
__________________
Feel free to e-mail me if I forget to respond ;)
ohsosexybrit@gmail.com

Last edited by itsallkizza; 12-26-2008 at 01:18 AM..
itsallkizza is offline   Reply With Quote
Users who have thanked itsallkizza for this post:
Cubefreak101 (01-14-2009)
Old 12-26-2008, 01:46 AM   PM User | #3
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
install firebug.
right-click on or next to button and select "inspect element"
find the html tag of the button. it is probably a <input type="button"> tag.
look for an onclick attrib on the tag, and copy the value of the attribute.
click the console tab of firebug and pase the code into the console.
click run, and the result should be the same as clicking the button.


if there is no onclick attrib, it's a little trickier.
you need an id for the input.
if it has one, great.
if not, while inspecting the input, right click the tag and select "new attribute", type "id" press enter and type "test1" and press enter.

click back on the console tab and type in $("test1").onclick.toString()

the code you need to run will appear in red text. copy it and paste it into a function, or run it from the console to simulate a click.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote
Old 12-26-2008, 02:38 AM   PM User | #4
itsallkizza
Senior Coder

 
Join Date: Oct 2008
Location: Long Beach
Posts: 1,196
Thanks: 36
Thanked 164 Times in 164 Posts
itsallkizza will become famous soon enough
But if the onclick/submit function is form posting or ajax posting to a page not on his domain (in this case, on his computer) then the results won't show up... am I wrong? If you can simulate a POST on a foreign domain (afaik impossible), that's a huge security issue.
__________________
Feel free to e-mail me if I forget to respond ;)
ohsosexybrit@gmail.com
itsallkizza is offline   Reply With Quote
Old 12-26-2008, 04:53 AM   PM User | #5
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by itsallkizza View Post
But if the onclick/submit function is form posting or ajax posting to a page not on his domain (in this case, on his computer) then the results won't show up... am I wrong? If you can simulate a POST on a foreign domain (afaik impossible), that's a huge security issue.
you can post to other domains without issue. any form can be set to any domain. some browsers will ask for a confirmation, but all allow it by default given that. noscript and other security watchdogs may not approve, but if a user is doing that, they probably know how to fix it for themselves to allow such an operation if they want.

i post to tumblr from 192.168.x.x to update my blog for instance.

i was thinking of approaching it more from a greasemonkey/userscript approach, but i suppose an http solution is possible as well, especially if you just need to build a GET string, and open the window of a search. the "not my page" thing threw me into a greasemonkey mindset...


if you need to work with the data in javascript, you will have to use a greasemonkey approach like i outline.

if you just want to view a search result page, you can easily do that by building the url, and opening a window to it, as in http://www.google.com/search?q=obama
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote
Users who have thanked rnd me for this post:
itsallkizza (12-26-2008)
Old 12-26-2008, 05:04 AM   PM User | #6
itsallkizza
Senior Coder

 
Join Date: Oct 2008
Location: Long Beach
Posts: 1,196
Thanks: 36
Thanked 164 Times in 164 Posts
itsallkizza will become famous soon enough
Quote:
you can post to other domains without issue.
- I was unaware of this. I feel so dumb, I've been doing web development for 8 years now... lol
__________________
Feel free to e-mail me if I forget to respond ;)
ohsosexybrit@gmail.com
itsallkizza is offline   Reply With Quote
Old 12-26-2008, 05:33 AM   PM User | #7
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,452
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
Quote:
Originally Posted by itsallkizza View Post
- I was unaware of this...lol
one of the best kept secrets of webdev?


it just seems like you shouldn't be able to, i know.
it weird we don't hear more about this.

the same origin policy really only applies to incoming data (except jsonp).
img pings, window.opens, and xdomain POSTs allow virtually unrestricted outbound traffic.

of course, you cannot read any cross-domain submit feedback, so javascript won't know if a POST worked or not, though you can send it to a new window/iframe for visual confirmation...
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.8% IE9:11.4% IE10:6.5%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:59 PM.


Advertisement
Log in to turn off these ads.