Micro Focus QTP (UFT) Forums
VB SCRIPT to click on specific links on webpage and store related data - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: VB SCRIPT to click on specific links on webpage and store related data (/Thread-VB-SCRIPT-to-click-on-specific-links-on-webpage-and-store-related-data)



VB SCRIPT to click on specific links on webpage and store related data - ACCBAJPA - 04-01-2013

Hi, I am new to DP, I need to automate the following scenario.

open http://www.emc.com/utilities/globalsiteselect.jhtml

then one by one click on all the country name displayed on the webpage ie afganistan, albania, algeria.....till Zambia, and for each country link clicked, record the URL its navigating to and the country name displayed at the right top of page, for example when you click Afghanistan it opens http://middle-east.emc.com/index.htm?fromGlobalSiteSelect and the country name displayed at the right top is Middle East. so the result should be
Afghanistan-->http://middle-east.emc.com/index.htm?fromGlobalSiteSelect--> Middle East
Please help. I badly need to automate .


RE: VB SCRIPT to click on specific links on webpage and store related data - ACCBAJPA - 04-02-2013

Code:
I have come up with the following code for the above problem,it runs fine for the first iteration, but it throws general run error at the second iteration, where the value of i=1. what is causing this error ??

'invoke the global site selector page
Systemutil.Run "iexplore.exe",Datatable("in_URL", dtLocalSheet),"open"
    wait 10
'__________________________________________________________________________________

Set obj=Description.Create()
obj("micclass").value="Link"
Set links=Browser("EMC : Global Site Selector").Page("EMC : Global Site Selector").ChildObjects (obj)
countLinks=links.Count-3
msgbox "Num of countries" & links.Count-3
'____________________________________________________________________________________

'Create a new Microsoft Excel object
Set myxl = createobject("excel.application")
myxl.Workbooks.Open "C:\Users\accbajpa\Desktop\qtp.xls"
myxl.Application.Visible = true

'this is the name of  Sheet  in Excel file "qtp.xls"   where data needs to be entered
set mysheet = myxl.ActiveWorkbook.Worksheets("Sheet1")
'_____________________________________________________________________________________
For i=0 to countLinks
tag= links(i).GetROProperty("name")
links(i).click
href=Browser("EMC : Global Site Selector").Page("EMC:open page").GetROProperty("url")

'_______________________________________________________________________________________
'Enter values in Sheet1.

mysheet.Range("A2").Offset(i,0).value=tag

mysheet.Range("B2").Offset(i,0).value=href

'__________________________________________________________________________________________
'go back to the page

browser("EMC : Global Site Selector").Back
Browser("EMC : Global Site Selector").Page("EMC : Global Site Selector").Sync

'________________________________________________________________________________________
Next
'________________________________________________________________________________________
'Save the Workbook
myxl.ActiveWorkbook.Save