Xpath object identification is a new feature in QTP 11.
Dim oPage
Set oPage=Browser("name:=Google").Page("title:=Google")
oPage.WebEdit("xpath:=//INPUT[@name='q']").Set "advancedqtp"'Entering value in Google textbox.
oPage.WebButton("xpath:=//INPUT[@value='Google Search']").Click'Clicking Google Search button.
Identifying using Id attribute
1. obj.WebEdit("xpath:=//input[@id='htmlID']").Set "QTP"
Identifying using Type attribute
1. obj.WebEdit("xpath:=//input[@type='text'][1]").Set "QTP"'Setting value in first textBox
Identifying using Tagname
1. obj.WebList("xpath:=//select[1]").Select "London"'Highlighting first listBox
Identifying using Innertext
1. obj.Link("xpath:=//a[.='Google']").Click'Clicking Google link
Identifying WebTable based on Rowcount
1. obj.WebTable("xpath:=//table[count(.//tr)=2]").Highlight 'Highlighting the table which has only two rows
http://unmesh.me/2011/11/16/using-dom-xpath-css-for-object-identification-in-qtp-part-1/
本文介绍QTP11中XPath对象识别的新特性,通过实例展示了如何使用XPath表达式定位网页元素,包括使用ID属性、类型属性、标签名、内部文本和表格行数来识别对象。
469

被折叠的 条评论
为什么被折叠?



