Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Dec 2008
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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.
    Last edited by itsallkizza; 12-26-2008 at 01:18 AM.
    Feel free to e-mail me if I forget to respond ;)
    ohsosexybrit@gmail.com

  • Users who have thanked itsallkizza for this post:

    Cubefreak101 (01-14-2009)

  • #3
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,398
    Thanks
    11
    Thanked 595 Times in 575 Posts
    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 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • #4
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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

  • #5
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,398
    Thanks
    11
    Thanked 595 Times in 575 Posts
    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 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%

  • Users who have thanked rnd me for this post:

    itsallkizza (12-26-2008)

  • #6
    Senior Coder
    Join Date
    Oct 2008
    Location
    Long Beach
    Posts
    1,196
    Thanks
    36
    Thanked 164 Times in 164 Posts
    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

  • #7
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,398
    Thanks
    11
    Thanked 595 Times in 575 Posts
    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 13/9/26)
    BROWSER STATS [% share] (2014/9/03) IE7:0.1, IE8:4.6, IE11:9.1, IE9:3.1, IE10:3.0, FF:17.2, CH:46, SF:11.4, NON-MOUSE:38%


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •