Clicking a text area within a web page was proving rather difficult using just the standard controls within water i.e. click event etc which you use for objects like buttons & text boxes. The area was contained within 2 iframes, a table object and finally a paragraph object p which was part of a document. To activate the area manually you simply click the area with the mouse and this activated not only the text area for adding text directly to the page but also activated the control toolbar which was otherwise grayed out stopping you from using many of the pages features. But this task proved very difficult to emulate within code. The final code which worked was used like a reference map to drill down onto the required paragraph and then using not one but three fire events finally emulated the simple mouse click. Here is the code with full comments as to what’s happening:
#First create a variable ‘$mainWindow to hold the first iframe reference
$mainWindow = $browser.frame(:id, frame1)
#Now create a new variable $mainContent to hold the first reference and reference the next iframe.
$mainContent = $mainWindow.frame(:id, frame2)
#Having got these references set the focus to its associated document body
$mainContent.document.body.focus
#Now set a reference to the first text within the document area using index (i.e. The first paragraph, p)
$firstParagraph = $mainContent.p(:index, 1)
#Set focus on this paragraph
$firstParagraph.focus
#Now fire the events of ‘onmousedown’, ‘onmouseup’ & ‘onclick’. You need to fire all of these events
$firstParagraph.fire_event("onmousedown")
$firstParagraph.fire_event("onmouseup")
$firstParagraph.fire_event("onclick")
And that’s it. The text area was activated which in turn activated the main toolbar to access other features. Certainly not so straight forward as I first thought.


0 comments:
Post a Comment