Good evening, I am a beginner to QTP, I need help, I developed a complex procedure for the reading of the tariffs within a page (developed in Javascript) and programming with powerful descriptive, for each share untreated, recognize the object .getROProperty ("InnerText") and put it in a variable for me with databases.
Indexes are many but all have the same properties (micclass, html tags) only changes the class and html id.
Class and html id recover them to function as a dataTable.
I have created a specific function that deals with the reading of the indices on the basis of a pair of collection value able to define only the object.
This is the part of script (function) that i need to recognize objects:
Function recover_q_cvq (q_cvq_ogg, ogg_class)
' Dim variables
Dim object_collection
Dim r_object
Dim rate_cvq
Dim count_object
Dim rate_trim
print "Object:" & q_cvq_ogg
print "Class:" & ogg_class
' recover rate with object collection, micclass, html tag, class, html id
Set object_collection = Description.Create()
object_collection("micclass").Value = "WebElement"
object_collection("html tag").Value = "DIV"
object_collection("class").Value = ogg_class
object_collection("html id").Value = q_cvq_ogg
object_collection("visible").Value = "True"
Set r_object = Browser("(H) Gestione Quote").Page("(H) Gestione Quote").ChildObjects(object_collection)
r_object.RefreshObject
count_object = r_object.count
If count_object = 1 Then
rate_cvq = r_object(0).getROProperty("innertext")
print "Object rate: " &rate_cvq
rate_trim_cvq = Replace(rate_cvq,",","")
recover_q_cvq = rate_trim_cvq
'empty variables object_collection,r_object,count_object
Set object_collection = nothing
Set r_object = nothing
Set count_object = nothing
Else
print "Object is not collected"
print "Error:" & err.number
print DescribeResult(err.number)
End if
End Function
The script works well and I have the variable rate_cvq object that interests me only during the execution often that QTP stops recognize the object suddenly, for no apparent reason, and despite the collection is not complete and therefore not recognize the ChildObject collects the object. When it happens from then on no object is recognized until the end of the test.
This anomaly occurs randomly and never at the same point and this, the same rate in an execution is detected while in another not. This makes me think that the script does not have problems.
Can someone please help me? I have to add some other property to the script? where am I wrong? Thank you very much in advance for your reply.
Cristiano
Related
I have this piece of code here, that's supposed to find an HTML element on this Reddit page and then return a value from it, and then store that in a zero-based 1d array. (I have an internet explorer instance called IE)
Dim awardelements As Object
Dim awards As String
awardelements = IE.document.querySelector("#siteTable > div")(0)
awards = awardelements.getAttribute("data-gildings")
results(i + 1, 14) = awards
So I'm trying to get the value of "data-gildings" (the # of awards the post got), but I'm getting an automation error on the awardelements = IE.document.querySelector("#siteTable > div")(0) line. I'm not sure I can use the JS querySelector like that tbh so that might be the problem. I'd appreciate it if someone could point me in the right direction!
Thanks ^^
querySelector returns a single node not a collection you can index into. And you need Set keyword as mentioned.
Dim awards As Object, awardCount As String
Set awards = ie.document.querySelector("#siteTable > div")
awardCount = awards.getAttribute("data-gildings")
I'm writing a chrome extension that will add helper text instructions/reminders to specific location in the "new order" form we use at work. I'm really new to coding (basically using this project as a way to learn). I've created something that works - but I'm convinced there's a more elegant solution that I just haven't been able to figure out.
var helpText = "this is the message"
var customAlert = makeAlert(helpText) //create html container for msg
function makerAlert(helpText){...} //createElem, add class/style, append children
I'm okay with that bit (above). But should i be storing information on each message in objects instead? why would/wouldn't i? what information would go in it?
function alertPlacer(customAlert){
var par = document.getElementsByClassName("class-name")[i];
var sib = par.childNodes[j];
par.insertBefore(customAlert, sib);
};
really struggling with this bit (above). I have actually made alertPlacer() functions for each message because i can't figure out how to create a function that will take different class name & index parameters. should i be breaking this up more? if i stored these bits of info in an object, would that be useful?
relevant info:
because the target locations are within a form, almost nothing has an "id" attribute. so i have to use getElementsByClassName & an index.
for each message, I know the target parent className & index and the child node index to "insert before".
i would like to stick with javascript-only solution.
functions can take multiple arguments:
function alertPlacer(customAlert,className,parIndex,childIndex){
var par = document.getElementsByClassName(className)[parIndex]; var sib = par.childNodes[childIndex];
par.insertBefore(customAlert, sib);
};
And you call your function like
alertPlacer(yourAlert,"class-name",6,9);
I'm in the middle of creating a program in the browser which compares the selections of the user with a list of pre-defined holidays using Objects. I tried to create an object from the selections of the user to use in comparisons and select the most matching holiday, however when I try to select the value (adding .value) it seems to break the flow of Java, and none of the code read afterwards is read.
var climateVar = document.getElementById('climateselect')/.value\;
var accVar = document.getElementById('accomadationselect')/.value\;
var durationVar = document.getElementById('duration')/.value\;
var userInput = new Input(climateVar/.value\, accVar/.value\, durationVar/.value\);
for (var key in userInput) {
var woo = userInput[key];
document.getElementById('someDiv').innerHTML += woo/.value\;
}
without any .value/s, this prints[object HTMLSelectElement]null[object HTMLSelectElement] - (I changed "getElementById" to "querySelector" which simply made it print "nullnullnull")
, but when I try to add .value anywhere, the entire script stops working, and so everything under this will not run. Why on earth would adding .value stop the script from working? Nothing else changed.
Also, I'm a novice at this, this was meant to be a practice project, but I've been stuck on this for about a day now. any other advice you might feel like giving would also be appreciated
everywhere I typed /.value\ I've tried to add .value, and it has had the effect of stopping the code
Are you sure you are calling value on a valid object? The object has to exist and support .value to get a result - e.g.
http://jsfiddle.net/pherris/t57ktnLk/
HTML
<input type="text" id="textInput" value="123"/>
<div id="divHoldingInfo">123</div>
JavaScript
alert(document.getElementById('textInput').value);
alert(document.getElementById('divHoldingInfo').innerHTML);
alert(document.getElementById('iDontExist').value); //errors out
In a Lotus Notes Project it's simple to access the current document automatically in the QueryOpen method for example, extracting it from NotesUIDocument, which is a parameter.
Sub Queryopen(Source As Notesuidocument, Mode As Integer, Isnewdoc As Variant, Continue As Variant)
//Here I get the document
Dim doc as NotesDocument
Set doc = Source.document
End Sub
How can I do the same, but working on the web, using Javascript? Not necessarily in the QueryOpen method, of course.
If you just want to access document fields, then it is an easy task to do:
var doc = document.forms[0];
var yourfield = doc.YourFieldName; // take care: fieldname is case sensitive
// to get a field- value;
var theValue = yourfield.value;
// to set a field value
yourfield.value = "AnotherValue";
In XPages this is done completely different as there you have JavaScript classes with similar / same methods / properties as the NotesDocument- class to mimic the LotusScript behaviour
hey guys i'm working on some code for a class project and for some reason the demo code i got in class is not working the same way. the errors aren't making any since can i get some help debugging i know its probably retarded. thanks a lot in advance.
function BuildGrid()
{
//begin with a BeginVertical() call so that controls
//are stacked vertically
GUILayout.BeginVertical();
GUILayout.FlexibleSpace();
//begin loopping for the rows
for(var i=0; i<rows; i++)
{
//call BeginHorizontal() so that controls are stacked
//horizontally
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
//begin looping for the columns
for(var j=0; j<cols; j++)
{
//getting the card object that resides
//at this location in the array
var card:Object = aGrid[i][j];
//the definition for the backside (visible part for the card
var img : String;
//check if the card is face up, if so, show the robot part
//if not show the wrench
if(card.ifFaceUp)
{
img = card.img;
}
else
{
img = "wrench";
}
//create a button using a picture instead of
//text. Getting the picture from the Resources
if(GUILayout.Button(Resources.Load(img),
GUILayout.Width(cardW)))
{
flipCardFaceUp(card);
//print to the debug the name of the picture
Debug.Log(card.img);
}
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
}
GUILayout.FlexibleSpace();
GUILayout.EndVertical();
}//end buildGrid
Class where ifFaceUP and img are defined
class Card extends System.Object
{
//is the card face up
var ifFaceUp:boolean = false;
//has the card been matched
var ifMatched:boolean = false;
//image for the card
var img: String;
//constructor
function Card(img : String)
{
this.img = img;
}
}
errors: http://puu.sh/2clHw
Looking at the script you emailed I can see that aGrid contains Objects of type Card. In ECMA JavaScript nothing is strongly typed. ECMA is the JS that runs in the browser. Your JS is .net code that runs on the server when the browser requests a certain page or used as a desktop application (not sure what type of app it is). Even though it's called JavaScript it only means that the syntax looks like JavaScript but since it's .net code it's completely different from JavaScript (ECMA).
One thing you can do with ECMA JS is:
var notStronglyTyped=22; // is int
notStronglyTyped = "hello";// changed to string
notStronglyTyped.subString();// can call subString now because it's a method of string
This will not work in .net since .net is strongly typed (and class based but that's not the problem at hand). Hence the int when you declare a variable:
var i:int=0;// the :int gives a syntax error in ECMA JS since it doesn't exist.
Strongly typed means that the variable needs to be declared or converted to a certain type before you execute functions or access properties that are accociated with that type. substring is a method of String but I can't call it on an int:
var i:int=0;
i.subString();//won't work in .net unless you cast it to another type.
((String)i).subString();//might work but I don't know the exact syntax for .net JS.
In short; when retrieving cards from aGrid I would suggest declaring them as Card since you don't need to type cast later when you declare it as Object. The array aGrid contains objects of type Card anyway so you should not get a warning or error there:
card = new Card("robot" + (i+1) + "Missing" + theMissingPart);
//instance card is of type Card
aCards.Add(card);//aCards contains items of type Card
....
aGrid[i][j] = aCards[somNum];
//aGrid is filled with items from aCards which in turn contains items of type Card
At some point in your code you do:
var card:Object = aGrid[i][j];
I am not sure why since aGrid contains Card type (everything is type Object because everything inherits from Object). So why not declare the variable card as an instance of Card?
var card:Card = aGrid[i][j];
That should solve your problem right there. I can't run the code here because I have not set up a .net develop environment but I'm sure that solves it.
You can look up articles on google on type casting (wikipedia) you can imagine the headaches that come with it when you fill an array or list with mixed types. This is where generics can lend a helping hand but it might be too early to get into that as it can make your head explode :-)