UFT is not finding the objects in IE - hp-uft

I have this code to find WebEdit objects. It works just fine finding objects on that page in chrome. It does not find the objects in IE. I get objCount = 2 for chrome and I get objCount = 0 for IE.
I have a function which opens the URL in specific browser.
Public Function OpenApplication(myURL, brType)
systemUtil.Run brType,myURL
End Function
I have a function which simply finds number of webedits objects.
Public Function NoOfWebEdits()
set basepage = Browser("micclass:=Browser").Page("micclass:=Page")
Set oEdit = Description.Create()
oEdit("micclass").Value = "WebEdit"
oEdit("Visible").Value = "True"
Set basepage = basepage.ChildObjects(oEdit)
objCount=basepage.count
NoOfWebEdits = objCount
End Function
My sample script for chrome:
OpenApplication("examplesite.com", "chrome.exe")
NoOfWebEdits
This works just fine. My page has two objects. NoOfWebEdits returned 2 as expected.
My sample script for IE:
OpenApplication("examplesite.com", "iexplore.exe")
NoOfWebEdits
It does not work. NoOfWebEdits returned 0 but I had two objects on the page. Based on my debug, I think UFT is still looking for chrome browser. UFT may not even looking at IE. How can I fix it? Is there way I can update my NoOfWebEdits function by saying activate IE browser and then count the number of objects?
Update # 1:
I had this code:
systemUtil.Run "iexplore.exe","www.google.com"
Print Browser("micclass:=Browser", "index:=0").GetROProperty("version")
I ran the code while chrome was open. I got "chrome 71.0"
I closed the chrome browser. I ran the code again and I got "IE 11"

Related

Need VBScript Code to toggle between two Webpages to copy content from one page and paste to another webpage

I am need of VBScript code to paste the content from one IE Explorer WebPage window to another IE Explorer WebPage window.
Currently i know the Process ID.
However I am not able to switch from one webpage to another. Or you can say my control does not move from one page to another.
#shellbye
Function Bmc(abc,xyz)
Set objIE = CreateObject("InternetExplorer.Application")
Call objIE.Navigate("// SOME APLLICATION") ' #opened the Web applcation
'# LOGGED INTO THE APPLCATION SUCCESSFULLY suing the VBScript
For i = 0 To objIE.Document.links.Length - 1
if objIE.Document.links(i).innerText ="Create a New Case" Then
Do Until objIE.ReadyState = PAGE_LOADED : Call WScript.Sleep(100) : Loop
objIE.Document.links(i).click '## THIS OPENS A NEW Window as link is an URL
Exit For
End If
End Function
In above, I am able to Open the new window after clicking the link i.e. at Step ##
Now I want to copy the content abc and xyz passed in the function Bmc(abc,xyz) to New Window opened through this.
However I am unable to move or us can say switch control to new window.

How do I debug JQuery-BootGrid data api to NancyFX

Question edited:
I wrote a page with jquery-bootgrid data API.
Its should be calling with AJAX to my NancyFX REST API, but it isn't.
Client side:
I'm serving the bootgrid from a local repo:
<script src="~/scripts/jquery.bootgrid.min.js"></script>
Maybe I shouldn't be using the .min.js file but rather the open one for debugging? If so, could you walk me through what to do, or point me in the direction?
The page code is
...
data-toggle="bootgrid" data-ajax="true"
data-url="/cars/0" data-method="GET"
Server side:
I have the html page served by NancyFx and is seen ok, except for the grid which is empty. There's an API module with a breakpoint in Visual Studio (running on localhost), with the following:
Get["/cars/{status:int}?current={current}&rowCount={rowCount}"] = parameters => ...
This code is never called. How can I force the debugger to catch ANY call before the routing is checked, and show me what's coming into the server?
I'm using the chrome debugger.
The current URL is not valid by Nancy standards. We don't add query string params to the route.
You would want to write something along the lines of:
Get["/cars/{status:int}"] = parameters =>
{
var status = (int)parameters.status;
var current = (string)parameters.current.TryParse("");
var rowCount = (int)parameters.current.TryParse(10);
...
}
Along those lines. (written off the top of my head)
An alternative approach is to bind the request like so:
Get["/cars/{status:int}"] = parameters =>
{
var request = this.Bind<MyRequest>();
...
}
public class MyRequest
{
public MyRequest()
{
RowCount = 10;
}
public int Status {get;set;}
public string Current {get;set;}
public int RowCount {get;set;}
}
Changing the nancy to Get["/cars/{status:int}"] = parameters => did the trick of catching the request.
The ajax wasn't being called because I lost the JQuery first line...
$(document).ready(function() {
To get the current and rowCount you need to use
var current = (int)Request.Form["current"];
var rowCount = (int)Request.Form["rowCount];
By the way, the Get wasn't working (I think its a Bootgrid bug) so I changed it to POST.
The simplest way to debug any jQuery library is by using the in-built debugger, it's kinda difficult for me to use chrome for that , so I use Firefox but if you are habitual of chrome then use it, the functionality is almost the same, but with Firefox you can directly switch to the events associated with any element in the html (in the inspect section)
Once you get into the debugger, set the breakpoint and refresh the page either by F5 or Ctrl+F5 if you selected the valid breakpoint you can see all the values associated with every variable also with every function.
Secondly, use the step-in option in the debugger to see where the exact line is pointing, if it's refering to any other file it will pop open automatically in the debugger menu. Firefox's spider monkey is much good at debugging and relating codes (that's totally my opinion).
3- for the api calls, the reason for data not being processed or not displayed, very much lies within the structure of the library,(on what parameters the data is called/fetched/retrieved), for this try to use the "watch expressions" option in debugger and try implementing the code on loaded dom in console section with trigger on the node which you think is bugged or which should display the value.

Can VBScript automatically log into a website and perform actions via CreateObject(InternetExploerer)?

I have an application that I use to play text based games. This application has scripting built into it it so you can create your own plugins. It supports various scripting languages such as JScript, VBScript, and LUA. What I want to do is create a plugin that is capable of logging into an account on a website and then perform various actions, like click a button or submit information. I've done a lot of research into this and I've made some degree of progress, but I keep running into issues. I'm not sure if what I'm trying to accomplish is even possible in the way I'm trying to do it.
So far I've been able to open up the browser and navigate to a page using CreateObject.
function WindowLoad
IE.Document.getElementByID("user").value = "testacct"
end function
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = 1
IE.navigate "http://www.mudconnect.com/SMF/index.php?action=login2"
Set IE.Window.OnLoad = GetRef("WindowLoad")
I'm now trying to figure out a way to fill the input fields with my information. At first I tried to use IE.Document.getElementByID(), however it was displaying this error message: Object required: 'Document.getElementByID(...)'
After doing some research I found out that this could be because it's trying to find the element before the page is loaded. So I decided to try the OnLoad method. However now I can't seem to find any way to reference the "Window." I've tried IE.Window.Onload, IE.Document.Window.Onload, and several other references, but it keeps saying: Object doesn't support this property or method: 'Window'. Anyone have any suggestions for me?
I've also tried:
Do While (IE.Busy)
Loop
IE.Document.getElementByID("user").value = "testacct"
I've managed to automatically fill out the form and submit it. My next goal was to be able to navigate while logged in and perform other actions such as voting. I wanted to set up a timer in my client to vote once a day, in case I forget to do it. However, the browsers behavior seems to be erratic once I try to perform another navigate. Here's my updated code:
dim pause
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = 1
IE.navigate "http://www.mudconnect.com/SMF/index.php?action=login"
while IE.Busy
pause = pause + 1
wend
world.note pause
IE.Document.Forms(1).Action = "http://www.mudconnect.com/SMF/index.php?action=login2"
IE.Document.Forms(1).Elements(0).value = "myUserName"
IE.Document.Forms(1).Elements(1).value = "myPass"
IE.Document.Forms(1).Submit
while IE.Busy
pause = pause + 1
wend
world.note pause
IE.navigate "http://www.mudconnect.com/cgi-bin/vote_rank.cgi?mud=Legends+of+the+Jedi"
while IE.Busy
pause = pause +1
wend
world.note pause
IE.Document.Forms(0).Submit
It doesn't appear to be navigating to the new page for some reason. It somehow gets sent somewhere else on the website. Another problem seems to be that it doesn't log me in if I set up a navigate to go somewhere else. I've spent hours reading up on the IE object documentation, but I can't seem to figure out what the issue is. I'm also curious if the IE.Document values get updated whenever you navigate to a new URL?
I solved this part of the problem. The best advice I have for anyone dealing with these particular issues is to pay close attention to the number of forms and elements on a page. View each form as a slot in an array of "forms." Then within each of these forms there is also an array of "elements." A lot of my problems were the result of not identifying the proper "form" or "element" within the array.
However, I still was unable to make this script login AND navigate afterwards. The solution I developed in light of this involved creating a new IE object and having it finish the task for me. It would be more elegant to have the IE object navigate a second time, but I was unable to figure that out. For now I'm going to flag this as solved, since I have found a way to make it work, but I am curious if there is a way to solve the issue I was having.
The easiest thing is to wait on the Busy property.
Dim IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = 1
IE.navigate "http://www.mudconnect.com/SMF/index.php?action=login2"
While IE.Busy
WScript.Sleep 1000
Wend
IE.Document.getElementsByName("user")(0).value = "testacct"
I believe WScript.Sleep will work for sleeping but if not look at this answer. I've never used VBScript but the principle is the same regardless of language.
Another problem, which I noticed when I went to that page, is that no element has the id "user." There's an input box with the name user but that's different. getElementsByName returns an array though.

WatiN, IE instances and grabbing them by their hWnd value

I am currently using WatiN to automate a proprietary website at my work, and am running into an issue with being able to grab an IE session by its hWnd value.
As of this writing, I can start IE, handle the pop-up that occurs (the site uses JavaScript to generate certain things dynamically), but cannot return to the main IE (the first) window once I have finished interacting with the pop-up.
Thoughts?
I have had trouble with this before and its because i was using local variables between postbacks to store the references to the elements.
don't do this
var btn = Browser.Button("clientid")
btn.Click(); //assume that this triggers a postback
var result = btn.Text;
do this
Browser.Button("clientid").Click();
result = Browser.Button("clientid").Text;

Dynamic Elements are not appearing in IE8 until there is a mouse click

I have an Ajax request that returns search results, and I am dynamically creating DOM elements to display those results. This is working as expected in all the browsers I've tested except for IE8.
The request is returning fine, the JavaScript is running successfully, and the elements are being created, but the elements are not being displayed in the page. They only appear after a mouse-click somewhere on the page.
I ran a quick test that ran the callback code without the Ajax request, and it behaved as expected there. So I'm wondering if this has something to do with the way IE8 is managing the callback thread. Has anyone else seen behavior like this, or have insight on it?
The callback is fundamentally very simple. I have reproduced with this:
function catchResults(response) {
var contentBlock = document.getElementById('divResults');
var divResults = document.createElement('div');
var txt = document.createTextNode("Results");
divResults.appendChild(txt);
contentBlock.appendChild(divResults);
}
I am using JQuery.ajax to make the call.
I have seen the proper behavior in FireFox and Chrome.
Thanks for the help!
I ran into this problem not so long ago on IE8.
I think this might be a problem with IE8 not re-rendering the elements in question.
An easy way to confirm this is to add a class to the parent element and then remove it. This should trigger IE8 to re-render the element.
If contentBlock is the parent element then you could test with the following:
Javascript version:
// Variable storing the test class name
var testClass = "testClass";
// Add test class to element
contentBlock.className += " "+testClass;
// Remove test class from element
var reg = new RegExp('(\\s|^)'+testClass+'(\\s|$)');
contentBlock.className=contentBlock.className.replace(reg,' ');
jQuery version:
// Variable storing the test class name
var testClass = "testClass";
// Add test class to element and then remove it
$('#divResults').addClass(testClass).removeClass(testClass);
Just put it at end of the function after you appendChild. Hopefully this should fix your issue.
Reference: http://www.openjs.com/scripts/dom/class_manipulation.php

Resources