SEARCH
TOOLBOX
LANGUAGES
modified on 4 July 2010 at 20:41 ••• 2,781 views

O2 Scripts/WatiN/Open page and show html elements in new window

From

Jump to: navigation, search

this example shows how to use WatiN to start a new instance of Internet Explorer and open a pop-up window with details about all page's HTML elements

screenshots

  • open O2's Simple Script Editor and past the code included below

Image:5_26_2010_2_44_18_PM_tmp3831.jpg

  • click 'Execute' and an new Instance of IE will open

Image:5_26_2010_2_49_05_PM_tmp3832.jpg

  • together with a pop-up window that will show the current Html Element details

Image:5_26_2010_2_50_49_PM_tmp3845.jpg

  • it is possible to manipulate the live HTML elements in real time
  • for example:
    • expand the 'INPUT' node
    • select the first 'Google Search' node
    • enter 'TEST SEARCH' in the Value element (bottom of the Properties view)

Image:5_26_2010_2_53_23_PM_tmp3853.jpg

  • note how the value was reflected in the Internet Explorer instance

Image:5_26_2010_2_56_09_PM_tmp3854.jpg

source code

var ie = "http://www.google.com".ie();
var hostPanel = O2Gui.open<Panel>("WatiN element details",400,400);
var controls = hostPanel.add_1x1("Html elements", "Propeties");
var propertyGrid = controls[1].add_PropertyGrid();
controls[0].add_TreeView()
		   .add_Nodes(ie.elements().indexedByTagName())
		   .sort()
		   .showSelection()
		   .beforeExpand<List<Element>>(
		  		(treeNode, elements) => 
		  					{
		  						try { treeNode.add_Nodes(elements);}
		  						catch(Exception ex) { ex.log("in beforeExpand<List<Element>>");}
		  					})
		   .afterSelect<Element>((element)=> propertyGrid.show(element))
		   .afterSelect<List<Element>>((elements)=> propertyGrid.show(elements[0]));
 
 
//O2File:WatiN_IE_ExtensionMethods.cs    
//O2File:WatiN_IE.cs
//using SHDocVw
//using WatiN.Core
//O2Ref:Interop.SHDocVw.dll
//O2Ref:WatiN.Core.1x.dll
MediaWiki Appliance - Powered by TurnKey Linux