DOM and IE Automation



There are many forums and posts from testers trying to automate scripts by using DOM(Document Object Model) of the internet explorer.

Here is a script that i used recently along , that will help anyone using the DOM and windows shell scripting :


Option Explicit

Sub WaitForLoad(obj)
    Do While ie.Busy
    Loop
    Do While obj.readyState <> 4
    Loop
    wscript.sleep(100)
End Sub

'Create ie and shell object
Set ie = WScript.CreateObject("InternetExplorer.Application")
Set WshShell = WScript.CreateObject("WScript.Shell")

'set the ie properties
ie.ToolBar = 1
ie.StatusBar = 1
ie.Width = 999
ie.Height = 999
ie.Left = 0
ie.Top = 0
ie.Visible = 1

'navigate to the web page
ie.Navigate("http:\\xyz.com")

'wait until the page has loaded before continuing
WaitForLoad(ie)

'Enter the user details
ie.Document.All.Item("txtUser").Value = strUser
'strUser = Trim (InputBox ("Plz enter the password"))
ie.Document.All.Item("pwdPass").Value = strPwd
ie.Document.All.Item("ddlHub").Value = "42d490a3-5107-435c-960d-a76e6d953ee9"
ie.Document.All.Item("butSubmit").Click
'ie.Document.getElementsByName("butSubmit").Item(0).Click

'wait until the page has loaded before continuing
WaitForLoad(ie)
WshShell.AppActivate "Main - Microsoft Internet Explorer"
For i=1 to 2
    wshShell.sendkeys "{TAB}"
    wscript.sleep(200)
Next
wshShell.sendkeys "{DOWN}"

ie.Document.getElementsByName("ctl00$ContentPlaceHolder1$btnView").Item(0).Click
ie.Document.All.Item("chkall").click

Set colLinks = ie.Document.getElementsByTagName("a")
intDay = Weekday(date)
If intDay = 2 then
    intOff = 2
elseif intDay = 3 then
    intOff = 4
End if

intcount = 0
For Each objLink In colLinks
    ' check text for link
    If InStr(UCase(objLink.innerHTML), "OFF") > 0 Then
    ' navigate to the first match and exit the for...next loop
        intcount = intcount + 1
     If intcount = intOff then
     'ie.Navigate objLink.href
     objLink.click
     Exit For
    End If
End If
Next

Set ie = nothing
Set colLinks = nothing
Set WshShell = nothing


Happy Testing!

Comments

  1. Technology Specific Guide for QTP is a new book that has got great feedback from all the readers. More on feedback and where to buy the book from here:
    http://bluemagic-automation.blogspot.in/

    ReplyDelete
  2. Thank you for the info. It sounds pretty user friendly. I guess I’ll pick one up for fun. thank u









    Travel Agency Automation

    ReplyDelete

Post a Comment

Popular posts from this blog

Software Testing @ Microsoft

Trim / Remove spaces in Xpath?