Source language: Translate to:

SendKeys Select All Web Browser Object?

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

SendKeys Select All Web Browser Object?

Postby domino » Wed Sep 20, 2006 12:46 pm

My page contains a Web Browser Object.

I would like to focus the Web Browser Object - Select All and Copy/Paste the contents to a variable.

I can do this from my manually from keyboard CTRL+A CTRL+C CTRL+V but not using SendKeys in NB.... even if I focus the Web Browser object.

Please can someone give me a steer on how to do this with SendKeys...

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Gaev » Wed Sep 20, 2006 1:29 pm

Dave:
I would like to focus the Web Browser Object - Select All and Copy/Paste the contents to a variable.

a) What do you expect to get by doing this ? As you may have seen from your manual action, you end up with the (bare) text of all selected items on the web page ... no format or layout codes etc.

b) Is this your intention ? ... Is the web page content of a specific nature that this makes sense ?

c) Have you looked at BrowserExport "WebBrowser1" "[Code]" ? ... would it suffice ?

d) If you truly want to replicate what the Ctrl+A, Ctrl+C, Ctrl+V sequence gives you, I can lookup the exact (javascript) code required to do this via the (new in v5.5) BrowserExecScript command.
I can do this from my manually from keyboard CTRL+A CTRL+C CTRL+V but not using SendKeys in NB.... even if I focus the Web Browser object.

It is difficult to do this at the best of times ... but even with the manual method, you will notice that it does NOT work as intended if the focused object is a TextEntry Box (with the vertical bar blinking within it) ... so it depends on which particular object within the web page has focus at the time.
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby domino » Wed Sep 20, 2006 2:29 pm

Hi Gaev

I`m compiling word lists for crosswords.

Currently my app gets the contents of a series of web pages - exports the web page contents to a file.

I then use string functions to get rid of the html code... separate the real words and phrases - compare and eliminate non relevant words from a master list... and add the remainder to the list....

This works OK except that there might be just half a dozen or so keywords not on my list contained in a webpage... but I might have to eliminate several thousand characters (mainly html, dhtml etc) to isolate those few words... obviously it takes a while to grind through the process.

If I could grab the page txt with CTR+A CTRL+C CTRL+V or some similir process it would make life so much easier as there wouldn`t be all the formatting to deal with....

focused object is a TextEntry Box (with the vertical bar blinking within it) ...


I've tried Tabbing in send keys to try and and get it to work but it didn`t help..

Hope this explains things a bit better....

Bsaically I want to capture the page contents.. but not the formatting

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby domino » Wed Sep 20, 2006 3:47 pm

Cracked it I think...

FocusObject "WebBrowser2"
SendKeys "" "{PgUp}"
SendKeys "" "{CtrlDn}a{CtrlUp}"
FocusObject "WebBrowser2"
SendKeys "" "{CtrlDn}c{CtrlUp}"


{PageUp} and then {Refocus}

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Gaev » Wed Sep 20, 2006 6:32 pm

Dave:

Thank you for the explanation ... always wondered why one would want to extract just the text from an html document.

Glad you found the workaround ... hope it works with all web pages ... but if you want to try a solution that works consistently (because it does not involve sending sequences of keystrokes), you might consider this ...

a) Make up a file called getInnerText.txt with this code (content) ...
Code: Select all
// get innerText of body
var gkText = document.body.innerText ;
window.external.nbSetVar( '[innerText]', gkText ) ;


b) Invoke these commands in NeoBook ... after a web page (html document) has been loaded in a Browser Object ...
Code: Select all
FileRead "[PubDir]getInnerText.txt" "All" "[thisString]"
BrowserExecScript "WebBrowser2" "[thisString]" "JavaScript"


... and [innerText] will have the text you desire.

Note you don't have to keep the javascript code in an external file ... could be [Embedded] (and use FileToVar instead of FiileRead) ... even type the commands directly in the second parameter of the BrowserExecScript command ... but inner DoubleQuotes and NewLine characters then have to be substituted by [#xx] characters.

f.y.i. the javascript code takes the innerText of the body of the document and first places it in a javascript variable called gkText ; then, using NeoBook v5.5's new facilities, copies the content to the NeoBook variable [innerText].
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby domino » Thu Sep 21, 2006 2:55 am

Thanks very much Gaev...

Am looking at your solution today as it looks more suitable to incorporate as an auto function. (Possibly with a more refined PreProcessing capability)

The SendKeys sort of Works OK but it's a bit of a sledgehammer process.

Cheers
Dave
User avatar
domino
 
Posts: 275
Joined: Sat Apr 02, 2005 7:11 am
Location: Notts UK

Postby Jay-Bird » Thu Sep 21, 2006 5:36 am

Thanks Gaev ...that get innerText snippet helps me also...I have had to work around getting text from html a lot.

Have a Great Day!
User avatar
Jay-Bird
 
Posts: 164
Joined: Fri Apr 01, 2005 7:01 am
Location: Louisiana , USA

Postby Gaev » Thu Sep 21, 2006 6:20 am

Jay-Bird:

Some other similar things that can now be done with this new interface in NeoBook v5.5 ...

a) get the html (text plus markup code) with this ...
Code: Select all
var gkHTML = document.body.innerHTML ;

b) if an html element has an id associated with it e.g. ...
Code: Select all
<div id="abcd" blah blah>this is some text</div>
... could be any other element like <p>, <span>, <li> etc. ... you can get just the text/html associated with it like so ...
Code: Select all
var myText = document.getElementById("abcd").innerText ;
var thisStuff = document.getElementById("abcd").innerHTML ;


Just keep in mind that Javascript is case-sensitive ... so variable gkText is different from GKText ... and those long instructions at the right of the equal sign must be typed exactly as shown.


I must say this v5.5 facility has extended NeoBook into a whole new dimension ... using these facilities, I can (Neo) script a base html document (I load with BrowserLoadFromStr) to ...

- create new elements (rich text, images and tables/cells)
- populate their content (text or images)
- change their styles (borders, margins, padding, colors, fonts etc.)
- move them
- resize them
- pass back values to NeoBook variables
- call back NeoBook subroutines on mouse clicks (and other events)

... and even set them up so user can move/resize them by dragging his mouse !!! ... lets you combine the power of Javascript/DTML/CSS with the simplicity of NeoBook scripting.
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby beno » Thu Sep 21, 2006 8:02 am

Hi Gaev,

- create new elements (rich text, images and tables/cells)
- populate their content (text or images)
- change their styles (borders, margins, padding, colors, fonts etc.)
- move them
- resize them
- pass back values to NeoBook variables
- call back NeoBook subroutines on mouse clicks (and other events)


Wow!, all of these (new to me) possibilities sounds incredible!!

Thanks for sharing these here.

Observing your examples, looks like all ot these will be accomplished using JavaScript (Ok, it´s time to study it carefully, just talking to myself)... am I wright?

.. and even set them up so user can move/resize them by dragging his mouse !!!


On this last one, are you thinking in JS too?

Saludos,

beno
User avatar
beno
 
Posts: 678
Joined: Fri Apr 01, 2005 9:03 am
Location: México

Postby Gaev » Thu Sep 21, 2006 9:38 am

Beno:

First some definitions ...

a) Basic Javascript is like NeoBook ... only it is Object Oriented ... comes with basic stuff like creating and setting variable values, if/else/endif, for and do/while loops ... and some basic native objects like date, math, string etc. ... and allows you to define your own functions (a bit like NeoBook Call'ed Functions).

b) Dynamic HTML (DHTML) and Cascading Style Sheets (CSS) are like what plugins are to NeoBook ... allow you to manipulate the html elements (like <body>, <div>, <img>, <p> etc.) that are part of the html document ... you can even create new elements at run time, insert them at a particular screen position (or sequence within the document) ... and define styles/styleGroups that can be associated with one/more of the html elements.

So what I have been building is a generic/reusable base html document ... that starts out with zero visible elements ... but includes many many functions that can be invoked with appropriate parameters ... this dummy document can be loaded into a NeoBook Browser Object using BrowserLoadFromStr.

Then, I can populate this document with new elements, define their position/size, define text, image files etc. for them, define/change styles, define mouse/keyboard) event call backs (to NeoBook subroutines) ... all using BrowserExecScript ... the "script code" is just one/more of my javascript functions with the appropriate parameters ... right now, I just load the "script code" from a text file ... so I can test and make changes while the pub is running ... but later I plan to have NeoBook Call'ed Functions ... so you can command the Browser Object without knowing any javascript/dhtml/css ... this last step is an easy ... but laborious process ... so it is best left to the very end.

My design places every element at an absolute specified location ... the alternative method (relative position) where you insert an element at a specific sequence within the document ... and which then automatically reformats the entire document ... can be overwhelming for nneophites ... so I do not plan of supporting it ... although it is not impossible.


As for the responses to mouse drags ... move or resize ... while this can be defined (allowed or not) from the NeoBook side ... I do not support any call back during the mouse move operation ... I believe there would be timing problems ... as the mouse move event fires continuously ... but call backs are definable on mouseClicks and doubleClicks (left, right and center buttons) ... and I have an example where a mouse click on a Table Cell calls a NeoBook subroutine which places a NeoBook TextEntry object exactly on top of the Table Cell ... allowing user to edit text ... and when done, have NeoBook update the content of the Table Cell.

I have tried out two alternate designs for the move/resize facility ... first one moves object underneath the mouse pointer upon drag of left mouse button and resizes upon drag of right mouse button ... second design moves object undernath the mouse pointer upon drag of left button and resizes if the Ctrl (or Shift or Alt) keys are also depressed at the same time as the drag of the left mouse button ... am also thinking of an option to retain aspect ratio while resizing.
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby beno » Thu Sep 21, 2006 10:25 am

Hi Gaev,

Thanks for your answers.

I create dynamic web pages with NB in my projects with BrowserLoadFromStr, mainly to deal with NBDB display.

I understand you are developing a special project, and sounds nice

What I find interesting in your contributions are new ideas and tools to deal while creating dynamic web pages, dealing with web content and user interaction.

This sounds real interesting for a project I have been working for months and I´m sure I´ll start adding these new ideas.

Saludos,

beno
User avatar
beno
 
Posts: 678
Joined: Fri Apr 01, 2005 9:03 am
Location: México

Postby Gaev » Thu Sep 21, 2006 10:44 am

Beno:
I create dynamic web pages with NB in my projects with BrowserLoadFromStr, mainly to deal with NBDB display.

Yes, I started the "dynoGrid" project in my quest for a dynamic Grid that can be used with something like NeoBookDB ... or just other applications that require grids ... like Crossword Puzzles, Sudoku ... as well as quick data entry of lots of values at a time.

As a separate project (dynoBrowser), I decided to build a facility using the Browser Object as a "Canvas" for rich text and image blocks ... buttons, check boxes etc. can also be added but I don't need them to be on a "Canvas" right now. Combining this second project with a facility to "snapshot any specified part of the pub window to a (bmp/jpg) file can make for a nice (greeting,business) card creator application.
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby beno » Thu Sep 21, 2006 10:53 am

Hi Gaev,

The project I´ve been working is a little content management system.

It is working now, it is built on a database so the user can create contributions and organize them, publish, etc.

I´m now thinking how to address the layout process. Untill now this is the weakest part because it offers only the possibility to select from ready made templates... in this point is where reading your contributions make me wonder here is another good idea to deal with the layout design of pages.

saludos,

beno
User avatar
beno
 
Posts: 678
Joined: Fri Apr 01, 2005 9:03 am
Location: México

Postby Gaev » Thu Sep 21, 2006 11:32 am

beno:

Here are some ideas ...

a) create elements of specified type, with associated styleGroup(s), at location x and y, layer (zIndex) and specified width and height ... and define content (text or image file)
Code: Select all
gkCreateItem("DIV","gkText1","gkTextStyle1","150 px","275 px",3,"300 px","100 px") ;
gkSetItemProperty("gkText1","innerHTML","Humpty Dumpty sat on a <b>wall</b>") ;

gkCreateItem("IMG","gkImage1","gkImageStyle1","50 px","400 px",1,"100 px","50 px") ;
gkSetItemProperty("gkImage1","src","Cave Toad.bmp") ;

And define StyleGroups like so ...
Code: Select all
gkDefineStyleGroup("gkImageStyle1","background-color","#44cc88") ;
gkDefineStyleGroup("gkImageStyle1","border-style","dashed") ;
gkDefineStyleGroup("gkImageStyle1","border-width","5px") ;
gkDefineStyleGroup("gkImageStyle1","border-color","#ff0000") ;

gkDefineStyleGroup("gkTextStyle1","background-color","Orange") ;
gkDefineStyleGroup("gkTextStyle1","border-style","solid") ;
gkDefineStyleGroup("gkTextStyle1","border-width","15px 5px 15px 5px") ;
gkDefineStyleGroup("gkTextStyle1","border-color","#000000") ;
gkDefineStyleGroup("gkTextStyle1","padding","4 px") ;


Note that any of the hard coded values can be substituted from NeoBook variables e.g.
Code: Select all
gkSetItemProperty("gkImage1","src","[myDBF.photoFile]") ;
gkSetItemProperty("gkText1","innerHTML","[myDBF.LastName]") ;


Also, you can create NeoBook functions so you can use
Code: Select all
Call "gkSetItemProperty" "Browser1" "gkImage1" "src" "[myDBF.picFile]"
Call "gkSetItemProperty" "Browser1" "gkText1" "innerHTML" "[myDBF.LastName]"
User avatar
Gaev
 
Posts: 3716
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby beno » Thu Sep 21, 2006 7:55 pm

Hi Gaev,

Ok, I started to play a little bit with this and have a question for you.

Now I´m able to open a webpage in a browser object and using the BrowserExecScript action and accesing the DOM Objects I can get the images and links inside the webpage and assign them to a NB variable with:

window.external.nbSetVar ('[MyVar]', document.images[0].src)

for example.

Later I tried to change the image file and found that if I use again the BrowserExecScript action and now do:

document.images[0].src = "file:///c:/path/myimage.jpg"

changes nice the image shown in the webbrowser object. Good till here!

My question is: suppose I would like to save the web page with the new image associated... I tried to:

BrowserExport "WebBrowser1" "[MyHTMLCode]"

But inside [MyHTMLCode] there is the original source for the image.

For my project it would be great if I´m able to save the HTML code with the "new" image reference.

I do not find how to accomplish this...

Any idea?

Saludos,

beno
User avatar
beno
 
Posts: 678
Joined: Fri Apr 01, 2005 9:03 am
Location: México

Next

Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 2 guests