Hi i am new to vbs and I am trying to create a vbs script to enter data into a field on a website and output the text returned to a text file
thats what I created so far:
Dim objIE
Set objIE = CreateObject("InternetExplorer.Application")
objIE.Visible = 1
objIE.navigate "http://translation.babylon.com/english/to-spanish/"
WScript.Sleep 100
Do while objIE.busy
Wscript.sleep 200
Loop
objIE.Document.all.Item("translator_input").Value = "sample text"
WScript.Sleep 100
Do while objIE.busy
Wscript.sleep 200
Loop
Call objIE.Document.all.Item("btnTranslate").Click
Objie.Quit
any ideas how to copy the transelation into a txt. or excel doc.?
Using Chrome's DOM inspector, it appears the translated text is put into this element:
<div id="resltext" name="resultext">
</div>
So you should be able to get the text by just looking for the ID and returning the value of innerText:
strTranslated = objIE.Document.All.Item("resltext").innerText
Related
Hi here I am reposting my query..
I have more than million records of employee in oracle table having emp id , name,designation ,office Id and address.
I need to generate letter for each employee using word template(include company logo image), and save it as pdf..
Single pdf for each office, containing letters pertaining to employees of that office...
I have written a batch file to extract data from oracle using pls all and save it in CSV.
Then I call open word document with open_document macro to merge CSV data with word template to generate letters and then save result as pdf
Batch file is
——————————————————
For /f "delims=" %%x in (office I’d.txt) do (
sqlplus userid/pass#emp #createcsv.sql %%x
move /Y %%x.lst %%x.CSV
echo %%x > datasourcename.txt
"C:\Program Files\Microsoft Office\root\Office16\winword.exe" /x /q newtemp.dotm
———————-—————————————
My dotm file contains macro named open_document to perform mail merge and close document after saving pdf file.
This works fine at home PC.. but in office coz macros are disabled,open_document is not working.
To over come that. I write macro code to vbscript file. And called it from batch file.
vbscript :::---
Dim strPath
Dim strDataSource
Dim strTemplate
Dim doc
Dim wrdApp
Set args = Wscript.Arguments
Set wrdApp = CreateObject("Word.Application")
wrdApp.Options.Pagination = False ' suppress pagination
With CreateObject("WScript.Shell")
strPath=.CurrentDirectory
End With
strDataSource = args.Item(0)
strTemplate = "Annexure11.dot"
'Start Word using mailmerge template
wrdApp.Documents.Open (strPath & "\" & strTemplate)
Set oMergeDoc = wrdApp.ActiveDocument
Set oMerge = oMergeDoc.MailMerge
oMerge.MainDocumentType = 0
msgBox "Before Open Datasource"
oMerge.OpenDataSource strPath & "\" & strDataSource &".csv"
msgBox "After Open Datasource"
oMerge.Destination = 0 ' 0 = wdSendToNewDocument
omerge.SuppressBlankLines=True
omerge.DataSource.FirstRecord=1
omerge.DataSource.LastRecord=-16
If omerge.State=2 then oMerge.Execute pause= false
'Do not display the mail merge document
wrdApp.Visible = False
'Save mail merge document as doc and pdf
wrdApp.ActiveDocument.SaveAs strPath & "\"& arg(0) &".pdf" , 17
wrdApp.ActiveDocument.SaveAs strPath &".doc"
omergedoc.Close False
wrdApp.Quit
Set wrdApp = Nothing
GetObject(, "Word.Application").Quit False
when I run the above code, I get msgbox with msg "Before Open Datasource" but never gets msg "After Open Datasource"
*Please suggest some alternate method to get desired output.
what I do is I navigate to a site then I want to find an element called "jobId"
Const PAGE_LOADED = 4
Set objIE = CreateObject("InternetExplorer.Application")
Call objIE.Navigate("http://172.25.25.32:8090/")
objIE.Visible = True
Do Until objIE.ReadyState = PAGE_LOADED : Call WScript.Sleep(100) : Loop
objIE.Document.all.Username.Value = "ashishgi"
objIE.Document.all.Password.Value = "apac2015#"
If Err.Number <> 0 Then
msgbox "Error: " & err.Description
End If
Call objIE.Document.all.gaia_loginform.submit
Set objIE = Nothing
when I use ViewSource this is the elements I want to use :
input type="submit" name="btnsubmit" value="Login" id="logincaption" class="button" style="color:#565656"
So, you're trying to click submit? Your explanation is difficult to interpret what you want the script to do. Based on the element you displayed on your sample is a submit button. It's been a while since I automated a form but I believe you want something to this effect.
objIE.Document.getElementsById("Username").Value = "ashishgi"
objIE.Document.getElementsById("Password").Value = "apac2015#"
' If you want to use the button by name
objIE.Document.all.item("btnsubmit").click
' If you want to use the button by ID
objIE.Document.getElementsById("logincaption").click
'if that fails, make it an object like this and action the click.
Set Submit = objIE.Document.getElementsById("logincaption")
submit.click
I want to write a dynamic VBScript for my web automation in UFT 12.02. I would like to pass a dynamic value as part of the link. here is my sample Line code:
set ObjExcel = CreateObject("Excel.application")
ObjExcel.workbooks.open "F:\Automation\Web\Business\WebTestData.xls"
For Curr= 1 To 20
USD = ObjExcel.sheets(1).cells(Curr,1).Value
If Browser("...").Page("...").Exist Then
Browser("...").Page("...").WebElement("WebElement").Click
'Attempt to click on Drop Down Link
Browser("...").Page("...").Link("USD").Click
End If
Next
"USD" will keep changing, i.e. I will be picking it from Excel.
Expected Result:
Generate a script that will attempt to click on different links as below:
Browser("...").Page("...").Link("EURO").Click
Browser("...").Page("...").Link("BP").Click
Browser("...").Page("...").Link("AED").Click
Browser("...").Page("...").Link("KSH").Click
Browser("...").Page("...").Link("IR").Click
Yes, you should use USD without double quote.
Dim currType, ObjExcel
set ObjExcel = CreateObject("Excel.application")
ObjExcel.workbooks.open "F:\Automation\Web\Business\WebTestData.xls"
For Curr= 1 To 20
currType = ObjExcel.sheets(1).cells(Curr,1).Value
If Browser("...").Page("...").Exist Then
Browser("...").Page("...").WebElement("WebElement").Click
'Attempt to click on Drop Down Link
Browser("...").Page("...").Link(currType).Click
End If
Next
set ObjExcel = Nothing
Note: I've changed USD with currType.
I have zero experience with UFT, but shouldn't using the variable USD instead of the string "USD" do what you want?
For Curr= 1 To 20
USD = ObjExcel.sheets(1).cells(Curr,1).Value
If Browser("...").Page("...").Exist Then
Browser("...").Page("...").WebElement("WebElement").Click
'Attempt to click on Drop Down Link
Browser("...").Page("...").Link(USD).Click
End If
Next
Hi I am facing an issue setting a value in WebEdit field. I have identified the object. But unable to set the value in the field as the field has Ajax functionality.
Set WshShell = CreateObject("WScript.Shell")
Set webeditObj = webeditObject("class", "grid-dropdownbox", "index" , "0")
Browser(browserObj).Page(pageObj).WebTable(webtableObj).WebEdit(webeditObj).Click
Browser(browserObj).Page(pageObj).WebTable(webtableObj).WebEdit(webeditObj).Set refBook.Item("book")
wait(3)
WshShell.SendKeys "{DOWN}"
wait(1)
WshShell.SendKeys "{ENTER}"
wait(3)
I can see the value in the input box. But when going to the next field the value of previous field is getting cleared.
Please help.
The issue has been resolved.
Please refer the below code. But still the wait time is not 100% sure. Sometimes its failing.
Function setValue(browserObj, pageObj, webtableObj, webeditObj)
Set WshShell = CreateObject("WScript.Shell")
wait(3)
WshShell.SendKeys "{DOWN}"
wait(3)
Browser(browserObj).Page(pageObj).WebTable(webtableObj).WebEdit(webeditObj).Click
WshShell.SendKeys "{DOWN}"
wait(5)
WshShell.SendKeys "{ENTER}"
wait(3)
End Function
This code gets me to the page and fills in the userid and password fields but after it does the submit I get a response from the application that the userid and password are not valid. If I don't execute the submit command but let the program stop at the page then manually click the login button then I successfully login. It appears eventhough the userid and paasword are being filled in correctly on the form, they are not getting passed through to the next page properly.
Any thoughts? I'm a VBsript newbie.
Set IE = WScript.CreateObject("InternetExplorer.Application", "IE_")
IE.Visible = True
IE.Navigate "https://cpprod.stjohns.edu/cp/home/displaylogin"
Do
WScript.Sleep 500
loop While IE.ReadyState < 4 And IE.Busy
IE.Document.getElementByID("user").value = "testacct"
WScript.Echo IE.Document.getElementByID("user").value
IE.Document.getElementByID("pass").value = "testpw"
WScript.Echo IE.Document.getElementByID("pass").value
IE.Document.getElementByID("cplogin").submit
Give the below a try and let me know your results...
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Visible = True
oIE.navigate WebPath
Do
WScript.Sleep 250
Loop While oIE.ReadyState < 4 And oIE.Busy
oIE.Document.All.Item("username").Value = sUser
WScript.Sleep 250
oIE.Document.All.Item("password").Value = sPass
WScript.Sleep 250
oIE.Document.All.Item("login").Click