简体   繁体   English

UFT自动化中的动态链接?

[英]Dynamic Link in UFT automation?

I want to write a dynamic VBScript for my web automation in UFT 12.02. 我想为UFT 12.02中的Web自动化编写一个动态的VBScript。 I would like to pass a dynamic value as part of the link. 我想将动态值作为链接的一部分传递。 here is my sample Line code: 这是我的示例代码:

set ObjExcel = CreateObject("Excel.application")
ObjExcel.workbooks.open "F:\Automation\Web\Business\WebTestData.xls"

For Curr= 1 To 20
    USD = ObjExcel.sheets(1).cells(Curr,1).Value
    If Browser("...").Page("...").Exist Then
       Browser("...").Page("...").WebElement("WebElement").Click
       'Attempt to click on Drop Down Link
       Browser("...").Page("...").Link("USD").Click
    End If
Next

"USD" will keep changing, ie I will be picking it from Excel. "USD"将不断变化,即我将从Excel中选择它。

Expected Result: 预期结果:

Generate a script that will attempt to click on different links as below: 生成一个脚本,将尝试单击以下不同的链接:

Browser("...").Page("...").Link("EURO").Click
Browser("...").Page("...").Link("BP").Click
Browser("...").Page("...").Link("AED").Click
Browser("...").Page("...").Link("KSH").Click
Browser("...").Page("...").Link("IR").Click

Yes, you should use USD without double quote. 是的,您应该使用不带双引号的美元。

Dim currType, ObjExcel

set ObjExcel = CreateObject("Excel.application")
ObjExcel.workbooks.open "F:\Automation\Web\Business\WebTestData.xls"

For Curr= 1 To 20
   currType = ObjExcel.sheets(1).cells(Curr,1).Value
   If Browser("...").Page("...").Exist Then
      Browser("...").Page("...").WebElement("WebElement").Click
      'Attempt to click on Drop Down Link
      Browser("...").Page("...").Link(currType).Click
   End If
Next

set ObjExcel = Nothing

Note: I've changed USD with currType. 注意:我已将currType更改为USD。

I have zero experience with UFT, but shouldn't using the variable USD instead of the string "USD" do what you want? 我对UFT的使用经验为零,但是不应该使用变量 USD而不是字符串 "USD"完成您的工作?

For Curr= 1 To 20
  USD = ObjExcel.sheets(1).cells(Curr,1).Value
  If Browser("...").Page("...").Exist Then
    Browser("...").Page("...").WebElement("WebElement").Click
    'Attempt to click on Drop Down Link
    Browser("...").Page("...").Link(USD).Click
  End If
Next

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM