Sendkeys does not work for Ajax WebEdit field - vbscript

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

Related

how to copy from a field from a website using vbs

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

WshShell.SendKeys - SLASH not allowed?

Today I am having difficulties with this following code:
x=msgbox("Your Text Here" ,0, "Your Title Here")
UserName=inputbox("After this message, you have 5 seconds to switch to Minecraft. Please enter the username you wish to type the song to:")
wscript.sleep 5000
WshShell.SendKeys "/msg" + UserName + "I know that we just met maybe this is dumb but it feels like there was something from the moment"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "that we touched 'Cause, it's alright, it's alright I wanna make you mine The way you're lightin'"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "up the room Caught the corner of my eye We can both sneak out the back door We don't have to say"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "goodbye 'Cause, it's alright, it's alright To waste time tonight Maybe I'm just a kid in love"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "Maybe I'm just a kid in love Oh, baby If this is what it's like falling in love Then I don't ever"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "wanna grow up Maybe I'm just a kid in love Maybe I'm just a kid in love Oh, baby"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "It'd be cool if it's the two of us But I don't ever wanna grow up 'Cause I got it all"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "Oh, oh, oh, oh, oh, oh And I got it all And I don't ever wanna grow up"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "Said, your place is kinda close And your 'Rents are out of town Baby, there's no pressure"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "But if you're down, I'm down 'Cause, it's alright, it's alright To just talk tonight"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "If you're feeling kinda crazy Turn down the lights We can take our time Do whatever you like"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "It's alright, it's alright I wanna make you mine Maybe I'm just a kid in love"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "Maybe I'm just a kid in love Oh, baby If this is what it's like falling in love"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "Then I don't ever wanna grow up Maybe I'm just a kid in love Maybe I'm just a kid in love"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "Oh, baby It'd be fine if it's the two of us But I don't ever wanna grow up"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "'Cause I got it all Oh, oh, oh, oh, oh, oh And I got it all And I don't ever wanna grow up"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "'Cause I got it all Oh, oh, oh, oh, oh, oh And I got it all And I don't ever wanna grow up"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "You make me feel like I got it all, yeah And you make me feel Like I'm just a kid in love"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "And you make me feel like I got it all And you make me feel like I don't ever wanna grow up"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "Maybe we're just kids in love Maybe we're just kids in love Oh baby If this is what it's like"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "falling in love Then we don't ever have to grow up Maybe we're just kids in love"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "Maybe we're just kids in love Oh baby When we're alone and it's the two of us"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "I can't get enough I've got it all, yeah I've got it all, yeah"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "And I've got it, and I've got it all And I've got it, and we've got it all And I've got it,"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "and I've got it all But I don't ever wanna grow up"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "Song: Kid In Love | By Shawn Mendes"
wscript.sleep 1000
WshShell.SendKeys "/msg" + UserName + "Sent by MineMessage (R) - By kittens643"
It is supposed to message a player in Minecraft this song, but this code is faulty. I have not done VBScript since last year, so this will be hard. Is / not allowed or is there a little typo?
Reading Windows Script Host SendKeys Method docs, all your characters are allowed except an unknown user's input.
However, set WshShell = WScript.CreateObject("WScript.Shell") missing in you code...
Consider testing it with notepad instead of Minecraft: all the code snippet outputs all in one line.

using vbscript to log into web page

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

How do I logout from vbscript?

I'm using a VBScript to run an application on my Win Server 2003, and I want it to log the user off after a set amount of time. Something along the lines of:
Set WshShell = WScript.CreateObject("WScript.Shell")
Set OExe = WshShell.exec("somecommand.exe")
WScript.Sleep 1000000
OExe.Terminate
<Insert LogOff code>
Something like
WshShell.Run "C:\windows\system32\shutdown.exe /l", 0, false
should do the trick
Wscript.Sleep(100000)
SET wshell = Wscript.CreateObject("Wscript.Shell")
wshell.exec("shutdown.exe -L -F")
Just tested this on a w7 box, seems to work alright.
Example using WMI:
Set oSystems = GetObject("winmgmts:{(Shutdown)}//./root/cimv2").ExecQuery("select * from Win32_OperatingSystem where Primary=true")
For Each oSystem in oSystems
'LOGOFF = 0
'SHUTDOWN = 1
'REBOOT = 2
'FORCE = 4
'POWEROFF = 8
oSystem.Win32Shutdown 0
Next

Call out to script to stop with attribute in wWWHomePage

I'm gettinga n error message in line 8 when I try to call out the script to stop when it finds teh attribute in the Web page: field in AD.
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserDN)
strwWWHomePage = objItem.Get("wWWHomePage")
If wWWHomePage 6 Then
wscript.quit
Else
Set ppt = CreateObject("PowerPoint.Application")
ppt.Visible = True
ppt.Presentations.Open "\\abngan01\tracking\ppt.pptx"
End If
You have:
If wWWHomePage 6 Then
I'm assuming you want it to say:
If wWWHomePage = 6 Then
Since the missing "=" will cause an error, but since that code really doesn't do anything anyway, other than just abort the script, you could simplify your code by only taking action if that value is not set, for example:
If objItem.Get("wWWHomePage") <> 6 Then
Set ppt = CreateObject("PowerPoint.Application")
ppt.Visible = True
ppt.Presentations.Open "\\abngan01\tracking\ppt.pptx"
End If
I'm also assuming "6" is some sort of flag you've set yourself, you might want to use something a little more descriptive like "PPTSTATUS006", or something along those lines.

Resources