Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automate lookup of Web page

Status
Not open for further replies.

rpillay

Programmer
Jun 16, 2011
7
US
Hi,

I am just starting out and I would greatly appreciate any help. Here's what I'm looking for:

I have to access a site on a separate pop up, using innerHTML, test 2 fields by ID on the pop up. Repeat the process up to five times or until the condition is satisfied. If the condition is not satisfied, close the pop up and retrieve the next.

- The fields and condition: (Amount > $1,000) OR (Total > $10,000)

- Controlling the iterations: Increment RecID by 1 of the HTTP:
The initial RecID will be provided by the user in the Main window. After each execution populate this field with the latest value.

- Main Window - I guess a button and an input field.

Note: Only 1 pop up window open after each execution.

Thank you,
Rick
 
Hi

First of all, is the page that will be opened in the popup from the same domain as your ?

If not, will your domain be allowed to perform cross-site request with AJAX ?

If none, better look into a server-side solution.

Feherke.
 
Hi Feherke,

It's not the same Domain. I currently keep changing the recID on the browser, then check the amounts. I was hoping for an automated solution.

Thanks,
Rick
 
Feherke,

Thanks for your response. I have very, very basic knowledge and I need help to get this started. To make things simple and practical,would it possible to script the following instead.

1. Main window, 2 buttons (PREV and NEXT) and one Input box. The user enters the starting number.

2. Pop up window BOX NUMBER. Previous pop up window should be closed before opening new pop up.

Thank you,
Really appreciate your input.
Rick
 
Hi

Rick said:
Previous pop up window should be closed before opening new pop up.
If you really want so...
Code:
[red]<!DOCTYPE[/red] [maroon]html[/maroon][red]>[/red]
[b]<html>[/b]
[b]<head>[/b]
[b]<meta[/b] [maroon]charset[/maroon][teal]=[/teal][green][i]"UTF-8"[/i][/green][b]>[/b]
[b]<title></title>[/b]
[b]<script>[/b]

[b]var[/b] w[teal]=[/teal]undefined
[b]function[/b] [COLOR=darkgoldenrod]go[/color][teal]([/teal]button[teal],[/teal]direction[teal])[/teal]
[teal]{[/teal]
  [b]var[/b] nr[teal]=[/teal][COLOR=darkgoldenrod]parseInt[/color][teal]([/teal]button[teal].[/teal]form[teal].[/teal]number[teal].[/teal]value[teal],[/teal][purple]10[/purple][teal])[/teal]
  [b]if[/b] [teal]([/teal][COLOR=darkgoldenrod]isNaN[/color][teal]([/teal]nr[teal]))[/teal] nr[teal]=[/teal][purple]0[/purple]
  nr[teal]+=[/teal]direction
  button[teal].[/teal]form[teal].[/teal]number[teal].[/teal]value[teal]=[/teal]nr
  [b]if[/b] [teal]([/teal]w [teal]&&[/teal] [teal]![/teal]w[teal].[/teal]closed[teal])[/teal] w[teal].[/teal][COLOR=darkgoldenrod]close[/color][teal]()[/teal]
  w[teal]=[/teal]window[teal].[/teal][COLOR=darkgoldenrod]open[/color][teal]([/teal][green][i]'[URL unfurl="true"]http://tek-tips.com/threadminder.cfm?pid=216&page='[/URL][/i][/green][teal]+[/teal]nr[teal])[/teal]
[teal]}[/teal]

[b]</script>[/b]
[b]</head>[/b]
[b]<body>[/b]

[b]<form[/b] [maroon]action[/maroon][teal]=[/teal][green][i]"#"[/i][/green][b]>[/b]
[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"button"[/i][/green] [maroon]value[/maroon][teal]=[/teal][green][i]"PREV"[/i][/green] [maroon]onclick[/maroon][teal]=[/teal][green][i]"go(this,-1)"[/i][/green][b]>[/b]
[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text"[/i][/green] [maroon]name[/maroon][teal]=[/teal][green][i]"number"[/i][/green][b]>[/b]
[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"button"[/i][/green] [maroon]value[/maroon][teal]=[/teal][green][i]"NEXT"[/i][/green] [maroon]onclick[/maroon][teal]=[/teal][green][i]"go(this,1)"[/i][/green][b]>[/b]
[b]</form>[/b]

[b]</body>[/b]
[b]</html>[/b]
But I would just give a name to the popup window and open all pages in the same window :
Code:
[b]function[/b] [COLOR=darkgoldenrod]go[/color][teal]([/teal]button[teal],[/teal]direction[teal])[/teal]
[teal]{[/teal]
  [b]var[/b] nr[teal]=[/teal][COLOR=darkgoldenrod]parseInt[/color][teal]([/teal]button[teal].[/teal]form[teal].[/teal]number[teal].[/teal]value[teal],[/teal][purple]10[/purple][teal])[/teal]
  [b]if[/b] [teal]([/teal][COLOR=darkgoldenrod]isNaN[/color][teal]([/teal]nr[teal]))[/teal] nr[teal]=[/teal][purple]0[/purple]
  nr[teal]+=[/teal]direction
  button[teal].[/teal]form[teal].[/teal]number[teal].[/teal]value[teal]=[/teal]nr
  window[teal].[/teal][COLOR=darkgoldenrod]open[/color][teal]([/teal][green][i]'[URL unfurl="true"]http://tek-tips.com/threadminder.cfm?pid=216&page='[/URL][/i][/green][teal]+[/teal]nr[teal],[/teal][green][i]'w'[/i][/green][teal])[/teal]
[teal]}[/teal]
Note that there are many alternatives to navigate over a successive pages by incrementing the numbers in the URL of the current page, most of them easier than the above popup-based crap.

Ps : Still curious about my question asked at 16 Jun 11 14:32.

Feherke.
 
Feherke,

Thank you, I really appreciate you taking time to put this together. Regarding the "pop up" - well I have a Mainframe background - so with my limited knowledge, this is the best I could come up with. Would love to know a simpler and easier way to navigate by incrementing the numbers in the URL.

So, I guess by now you realize why I didn't answer your question.

Thanks,
Rick
 
Feherke,

The script you gave me works perfectly. Perfect for my needs.

Thanks a million,
Rick
 
Hi

Rick said:
Would love to know a simpler and easier way to navigate by incrementing the numbers in the URL.
There I was just thinking aloud. Then I realized that you still not answered if the solution has to be public or only for yourself ( or limited community ). Those ways are all based on browser extensions or bookmarklets.


Feherke.
 
Hi Feherke,

The solution is just for myself.

Thanks,
Rick
 
Hi

Well, then GreaseMonkey can do much more for you.
Code:
[red]<!DOCTYPE[/red] [maroon]html[/maroon][red]>[/red]
[b]<html>[/b]
[b]<head>[/b]
[b]<meta[/b] [maroon]charset[/maroon][teal]=[/teal][green][i]"UTF-8"[/i][/green][b]>[/b]
[b]<title></title>[/b]
[b]</head>[/b]
[b]<body>[/b]
[b]<form[/b] [maroon]action[/maroon][teal]=[/teal][green][i]"#"[/i][/green] [maroon]id[/maroon][teal]=[/teal][green][i]"navi"[/i][/green][b]>[/b]
[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"button"[/i][/green] [maroon]value[/maroon][teal]=[/teal][green][i]"PREV"[/i][/green] [maroon]id[/maroon][teal]=[/teal][green][i]"prev"[/i][/green][b]>[/b]
[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"text"[/i][/green] [maroon]name[/maroon][teal]=[/teal][green][i]"number"[/i][/green] [maroon]id[/maroon][teal]=[/teal][green][i]"number"[/i][/green][b]>[/b]
[b]<input[/b] [maroon]type[/maroon][teal]=[/teal][green][i]"button"[/i][/green] [maroon]value[/maroon][teal]=[/teal][green][i]"NEXT"[/i][/green] [maroon]id[/maroon][teal]=[/teal][green][i]"next"[/i][/green][b]>[/b]
[b]</form>[/b]
[b]<ul[/b] [maroon]id[/maroon][teal]=[/teal][green][i]"list"[/i][/green][b]></ul>[/b]
[b]<iframe[/b] [maroon]id[/maroon][teal]=[/teal][green][i]"render"[/i][/green] [maroon]style[/maroon][teal]=[/teal][green][i]"display: none"[/i][/green][b]></iframe>[/b]
[b]</body>[/b]
[b]</html>[/b]
Code:
[gray]// ==UserScript==[/gray]
[gray]// @name           Rick[/gray]
[gray]// @include        [URL unfurl="true"]http://localhost/remote.htm[/URL][/gray]
[gray]// @include        file:///home/rick/remote.htm[/gray]
[gray]// ==/UserScript==[/gray]

[b]function[/b] [COLOR=darkgoldenrod]go[/color][teal]([/teal]direction[teal])[/teal]
[teal]{[/teal]
  [b]var[/b] number[teal]=[/teal]document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'number'[/i][/green][teal])[/teal]
  [b]var[/b] nr[teal]=[/teal][COLOR=darkgoldenrod]parseInt[/color][teal]([/teal]number[teal].[/teal]value[teal],[/teal][purple]10[/purple][teal])[/teal]
  [b]if[/b] [teal]([/teal][COLOR=darkgoldenrod]isNaN[/color][teal]([/teal]nr[teal]))[/teal] nr[teal]=[/teal][purple]0[/purple]
  nr[teal]+=[/teal]direction
  number[teal].[/teal]value[teal]=[/teal]nr

  [COLOR=darkgoldenrod]GM_xmlhttpRequest[/color][teal]([/teal][teal]{[/teal]
    method[teal]:[/teal][green][i]'GET'[/i][/green][teal],[/teal]
    url[teal]:[/teal][green][i]'[URL unfurl="true"]http://tek-tips.com/threadminder.cfm?pid=216&page='[/URL][/i][/green][teal]+[/teal]nr[teal],[/teal]
    onload[teal]:[/teal]process
  [teal]}[/teal][teal])[/teal]
[teal]}[/teal]

[b]function[/b] [COLOR=darkgoldenrod]process[/color][teal]([/teal]response[teal])[/teal]
[teal]{[/teal]
  [b]var[/b] render[teal]=[/teal]document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'render'[/i][/green][teal])[/teal]
  [b]var[/b] list[teal]=[/teal]document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'list'[/i][/green][teal])[/teal]
  render[teal].[/teal]contentDocument[teal].[/teal]body[teal].[/teal]innerHTML[teal]=[/teal]response[teal].[/teal]responseText
  [b]var[/b] thread[teal]=[/teal]render[teal].[/teal]contentDocument[teal].[/teal][COLOR=darkgoldenrod]getElementsByClassName[/color][teal]([/teal][green][i]'ttype1'[/i][/green][teal])[/teal]
  [b]while[/b] [teal]([/teal]list[teal].[/teal]firstChild[teal])[/teal] list[teal].[/teal][COLOR=darkgoldenrod]removeChild[/color][teal]([/teal]list[teal].[/teal]firstChild[teal])[/teal]
  [b]for[/b] [teal]([/teal][b]var[/b] i[teal]=[/teal][purple]0[/purple][teal],[/teal]l[teal]=[/teal]thread[teal].[/teal]length[teal];[/teal]i[teal]<[/teal]l[teal];[/teal]i[teal]++)[/teal] [teal]{[/teal]
    [b]var[/b] item[teal]=[/teal]document[teal].[/teal][COLOR=darkgoldenrod]createElement[/color][teal]([/teal][green][i]'li'[/i][/green][teal])[/teal]
    item[teal].[/teal]innerHTML[teal]=[/teal]thread[teal][[/teal]i[teal]].[/teal]innerHTML
    list[teal].[/teal][COLOR=darkgoldenrod]appendChild[/color][teal]([/teal]item[teal])[/teal]
  [teal]}[/teal]
[teal]}[/teal]

document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'prev'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]addEventListener[/color][teal]([/teal][green][i]'click'[/i][/green][teal],[/teal][b]function[/b][teal]([/teal]e[teal])[/teal] [teal]{[/teal] [COLOR=darkgoldenrod]go[/color][teal](-[/teal][purple]1[/purple][teal])[/teal] [teal]}[/teal][teal],[/teal][b]false[/b][teal])[/teal]
document[teal].[/teal][COLOR=darkgoldenrod]getElementById[/color][teal]([/teal][green][i]'next'[/i][/green][teal]).[/teal][COLOR=darkgoldenrod]addEventListener[/color][teal]([/teal][green][i]'click'[/i][/green][teal],[/teal][b]function[/b][teal]()[/teal] [teal]{[/teal] [COLOR=darkgoldenrod]go[/color][teal]([/teal][purple]1[/purple][teal])[/teal] [teal]}[/teal][teal],[/teal][b]false[/b][teal])[/teal]
Some explanation :
[ul]
[li]GreaseMonkey is a browser extension. It handles a set of scripts based on your instructions. Those scripts are almost regular JavaScript files with a metatag section. In the metatag section's [tt]@include[/tt] and [tt]@exclude[/tt] rules you tell to which URLs that script pertain and to which not. ( Read about the Include and exclude rules for more details. )[/li]
[li]When you visit a page, after the page finished loading, GreaseMonkey searches for the current URL in the active scripts' [tt]@include[/tt] and [tt]@exclude[/tt] rules. The scripts which pertain to that URL are executed in the current document's context.[/li]
[li]In the above script the 1[sup]st[/sup] [tt]@include[/tt] rule can be used if you have a web server running locally. For this you must have the remote.htm file in your web server's document root directory. ( Actually any web server will work. You can even use one where you have no access by changing rick.user.js to recreate remote.htm's important parts inside any document. Local web server is better for faster loading. )[/li]
[li]The 2[sup]nd[/sup] [tt]@include[/tt] rule can be used if you not have a web server running locally. For this you must have the remote.htm file in the specified directory and the [tt]greasemonkey.fileIsGreaseable[/tt] preference turned on in about:config.[/li]
[li]You can freely edit the file names, paths and domains as long as the [tt]@include[/tt] rules contain correct information.[/li]
[/ul]
Regarding the installation :
[ul]
[li]create the remote.htm file in the specified directory with the above content [/li]
[li]install GreaseMonkey[/li]
[li]visit remote.htm[/li]
[li]from the GreaseMonkey's menu execute the New User Script... command and put the above content into the created file[/li]
[li]if you want to use it without web server go to about:config and set [tt]greasemonkey.fileIsGreaseable[/tt] to True[/li]
[li]reload remote.htm[/li]
[li]then pushing the buttons should work ( will just list the threads of this forum )[/li]
[/ul]
Tested with GreaseMonkey 0.9.5 in FireFox 4.0.1 on Linux. For other browsers see Equivalents for other browsers section in the GreaseMonkey Wikipedia article.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top