What I have is a table of dollar amounts, some of which are links. Example:
$0.00
$1,000.00
$1.00
How do I say this most succinctly in QTP-land?
Set desCurrencyString = Description.Create
desCurrencyString("micclass").value = NOT "Link"
I suppose I could just use a boolean value to see where the link is and somehow capture the other parts of the list, possibly like this:
Set desCurrencyString = Description.Create
desCurrencyString("text").RegularExpression = True
desCurrencyString("text").value = "\$[0-9]*"
Set arrCurrencyStrings = Page.ChildObjects(desCurrencyString)
desCurrencyString("micclass").value = "Link"
arrCurrencyStrings.Remove(desCurrencyString) 'Or something, will be editing this line later
Simply loop through a WebTable.
To get cell text, use GetCellData(Row, Col) method of WebTable object.
To get a child object contained in a cell, use ChildItem(Row, Col, MicClass, intIndex) method of WebTable object.
Neither table rows, nor cells, spans, divs, etc. can be returned by ChildObjects function as they are not truly GUI object classes. (Though, if you would need it very much you could define such custom objects, but you'd have to manually set them up in Object Repository Manager).
Related
I know that with Descriptive programming you can do something like this:
Browser("StackOverflow").Page("StackOverflow").Link("text:=Go To Next Page ", "html tag:=A").Click
But is it possible to create some kind of string so I can assign more than one data value and pass it as single variable? I've tried many combinations using escape characters and I always get error.
For example in the case above, let's say I have more properties in the Page object, so I'd normally have to do something like this:
Browser("StackOverflow").Page("name:=StackOverflow", "html id:=PageID")...etc...
But I'd like to pass "name:=StackOverflow", "html id:=PageID" as a single variable, so when writing many objects I'd only have to write:
Browser(BrowserString).Page(PageString).WebEdit("name:=asdfgh")
And the first part would remain static, so if the parents' data needs to be modified I'd only have to modify two variables and not all the objects created in all libraries.
Is it possible?
If I was not clear enough please let me know.
Thank you in advance!
I think what you're looking for is UFT's Description object
This allows you finer grained control on the description since in descriptive programming all values are regular expressions but with Description you can turn the regular expression functionality off for a specific property.
Set desc = Description.Create()
desc("html tag").Value = "A"
desc("innertext").Value = "More information..."
desc("innertext").RegularExpression = False
Browser("Example Domain").Navigate "www.example.com"
Browser("Example Domain").Page("Example Domain").WebElement(desc).Click
If you want to represent this with plain string then it's a bit more of a problem, you can write a helper function but I'm not sure I would recommend it.
Function Desc(descString)
Set ret = Description.Create()
values = Split(descString, "::")
For Each value In values
keyVal = Split(value, ":=")
ret(keyVal(0)).Value = keyVal(1)
Next
Set Desc = ret
End Function
' Usage
Browser("StackOverflow").Page("StackOverflow").WebElement(Desc("html tag:=H2::innertext:=some text")).Click
Further reading about descriptive programming.
As an alternative to Motti's excellent answer, you could also Set a variable to match your initial descriptive object and then extend it as required:
Set myPage = Browser("StackOverflow").Page("name:=StackOverflow", "html id:=PageID")
after which you can then use
myPage.WebEdit("name:=asdfgh")
throughout the rest of the code, so long as the myPage object stays in scope...
I've one grid created on second page of page frame and linked to .PRG file for each time activate on different page. Under Activate events, each grid's column defined its own member class created under .PRG file.The problem is I couldn't able to access to each member control of grid's columns even I tried to change it but it will remain same class created under individual page's activate events.
I won't initialise the gird's column control base class on grid's init event because I need to set additive access to different .PRG file When access on different page. This problem of failed to access column member or control of grid won't be exists in form when I initalised grid's member control under grid's init events. BTW,i'm using vfp 6.
My Code under Page item Activate Events
set procedure to
set procedure to cn_pro additive
for count = thisform.page_.pages(thisform.page_.activepage).grid_list.columncount to 1 step -1
column_ = "column" + alltrim(str(count))
thisform.page_.pages( thisform.page_.activepage ).grid_list.removeobject( "&column_")
next
with thisform.page_.pages(thisform.page_.activepage).grid_list
.addobject("column1","column")
.columns(1).visible = .t.
.columns(1).bound = .t.
.columns(1).width = 75
.columns(1).header1.alignment = 2
.columns(1).header1.caption = "Mod_Qty"
.columns(1).removeobject("text1")
.columns(1).addobject("btn_qty","btn_quan")
.columns(1).currentcontrol = "btn_qty"
.columns(1).btn_qty.visible = .t.
.columns(1).btn_qty.caption = "Mod Qty"
.columns(1).sparse = .f.
endwith
create cursor tmpcur(btn_qty logical null)
use in select('tmpcur')
use in dbf('tmpcur') in 0 again alias tmpcur_
use in tmpcur
thisform.page_.pages(thisform.page_.activepage).grid_list.recordsource = ""
thisform.page_.pages(thisform.page_.activepage).grid_list.recordsource = "tmpcur_"
thisform.page_.pages(thisform.page_.activepage).grid_list.refresh()
**My class code in cn_pro.PRG file(Same example 1 problem)**
define class frm as form
procedure keypress
LPARAMETERS nKeyCode, nShiftAltCtrl
for each frm_ in _screen.forms
if alltrim(frm_.name) == "MAIN"
scan
with frm_.page_.pages( frm_.page_.activepage ).grid_list
**=>Example is here I've two record inside the grid,
**=>I want to change the property of button or access on it.**
.column1.btn_qty.enabled = .f.
**=>It will return Error message said "unknown member btn_qty" How to fix it?**
endwith
endscan
endif
endfor
endpro
enddefine
**My class code in cn_pro.PRG file(Same example 2 problem)**
define class frm as form
procedure keypress
LPARAMETERS nKeyCode, nShiftAltCtrl
for each frm_ in _screen.forms
if alltrim(frm_.name) == "MAIN"
scan
with frm_.page_.pages(frm_.page_.activepage).grid_list
**=>Example is here I've two record inside the grid,
**=>I want to change the property of button or access on it.**
.removeobject('column1')
**=>Remove entire column1 contained with** commandbutton "btn_qty"
.createobject('column1','column')
.column1.bound = .t.
.column1.text1.visible = .t.
.column1.sparse = .f.
.refresh()
**=> Previous CommandButton on column1 should be changed and
** replace with text here but It won't change and still be
** same commandbutton.Why, How to fix it?**
endwith
endscan
endif
endfor
endpro
enddefine
Hopefully anyone could solve my problem here.Thanks!
If i understand correctly, your approach will not work. You don't need to remove columns, you need to add/remove objects to the column and then set the columns current control property to the control you want.
If you want a variety of different controls to display for the same column, then you set the dynamiccurrentcontrol property to an expression that will look at a value and then return the name of the column.control that you want to display dependent upon the logical comparison in the expression.
I think I've ready found the solution, the reason why it unable detect button(control members fo grid) because it is created right after return focus to main form when you have grid created on page frame.
m.result = .t.
frm_.page_.pages(frm_.page_.activepage).btn_print.setfocus() =>to set it focus for later trigger btn_print's gotfocus
=>event,which will be able to change property's of member control of grids.
this.release =>exit "frm" class
Coding for btn_print gotfocus
if m.result=.t.
m.result = .f.
with this.parent.gid_list
.columns(1).btn_qty.enabled = .f.
endwith
endif
Struggle me for one day more until i could find out the reason and solution.
I have got a Kendo Grid and I want to access the data from the row whose detail I expanded. For testing purposes, I have this:
function detailExpand(e)
{
var aux = e.sender.MyModelId;
var aux2 = this.MyModelId;
...
But none of those variables have the MyModelId in it.
I have inspected it and I can't find the model properties unless inside the e.sender._data[index-here] but I don't know the index of the row whose detail I've expanded.
e.sender.dataItem(e.masterRow).MyModelId
http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#events-detailExpand
http://docs.telerik.com/kendo-ui/api/javascript/ui/grid#methods-dataItem
For the record, you should try to avoid using methods starting with an underscore (_). I believe kendo uses the underscore to show it's an internal method (a "private"). Unexpected behavior could occur.
I have declared variable in beforeFactory of BIRT Report.
For example:
This variable I am incrementing in table row render like:
Now when all the rows are rendered I want to set above variable to specific cell/ element. I tried
document.getElementName("numberOfMobilityFilesProcessed").text = numberOfMobilityFiles;
AND
reportContext.getDesignHandle().getElementByID
but they are not working out for me.
I had some problems with temporaly local variables used at multiple steps of datasource scripting so I always used global persisting.
After changing your variable you convert it to a String (because only Strings can be persisted) and before editing your variable again, you load the String from persisted context and convert it to the type you want (String to Integer are automatically converted by JavaScripts dynamic typed variables, but don't forget the toString() when you are saving otherwise you will risk an error).
Because you are using reportContext.setPersistentGlobalVariable your variable is accessable in every Element of your Report.
Example:
var rowNum = reportContext.getPersistentGlobalVariable("row_number");
if(rowNum == null){
rowNum = -1;
}
rowNum++;
reportContext.setPersistentGlobalVariable("row_number", rowNum.toString());
Ok, you have a text element displaying a number of row in a table element. The text element appears before the table in the report.
If you are using two separate tasks RunTask and RenderTask:
Add a report variable in your report (see "variable" node on the Data Explorer view). Then you can change the report variable in onCreate() event handler of the table row:
vars["numberOfSomething"] = vars["numberOfSomething"] + 1;
and access its value in an onRender() evenet handler of some text element, for instance DynamicText:
this.text = "Number of something: " + vars["numberOfSomething"];
If you are using RunAndRenderTask, you must look for another approach. In this case an order of onCreate() and onRender() calls is different. You could bind the same DataSet to the text element displaying the counter, as the one bound to the table. Than you can add an aggregation binding to the text element that will count all rows in the dataset.
I was trying to run below script, but it's giving me an error that says:
object doesn't support this property or method: "dbrowser.GetRoProperty"
SystemUtil.Run "iexplore.exe","http://usps.com/"
Set dbrowser = description.Create
dbrowser ("micclass").value = "Browser"
dbrowser("openurl").value = "https://www.usps.com"
dbrowser("title").value = "USPS - The United States Postal Service (U.S. Postal Service)"
print(dbrowser.getroproperty("title"))
Your dbrowser object is of type Description not Browser you need to create a Browser object based on this description. Replace the last line with:
Print Browser(dbrowser).GetROProperty("title")
Note, there are two changes here
Using Browser(dbrowser)
Removing the parens from the print sub.
Edit: also note that descriptions are regular expressions by default so the parens in the title may cause problems, you should mark it as not regex.
dbrowser("title").RegularExpression = False
Description.Create is used to create a 0-based Properties collection object. The variable dbrowser is preceded by the Set statement. Usage of Set statement binds an object as a reference to another object. Therefore, dbrowser becomes an object reference to the description object represented by Description.Create
A description object does not have a stand-alone use, but coupled with the ChildObjects method, it becomes an extremely powerful approach in dealing with AUT’s objects .For More Info, check link
So the code should be like
SystemUtil.Run "iexplore.exe","http://usps.com/"
wait(10)
Set dbrowser = description.Create
dbrowser ("micclass").value = "Browser"
dbrowser("openurl").value = "https://www.usps.com"
dbrowser("title").value = "USPS.*" ''Using Regular Expression here
Set colObject = Desktop.ChildObjects( dbrowser )
Print (colObject(0).GetROProperty("title"))