与 Exist 方法相关的问题

发布于 2024-09-16 01:35:28 字数 1265 浏览 2 评论 0原文

我在 QTP 中使用 Exist 方法时遇到问题..就好像我将 Exist 与 If else 一起使用那么它工作正常...但如果直接使用则不起作用...

例如:

Browser("Home").Page("Home_2").WebEdit("ctl00$uxMNJDefaultContentPlace").Click
Browser("Home").Page("Home_2").WebEdit("ctl00$uxMNJDefaultContentPlace").Set DataTable("mfgpartnumber", dtGlobalSheet)  ''#Read mfg# from datasheet

Browser("Home").Page("Home_2").Image("ctl00$uxMNJDefaultContentPlace").FireEvent "onmouseover"

Browser("Home").Page("Home_2").Image("ctl00$uxMNJDefaultContentPlace").Click 31,11
wait(15)

Browser("Home").Page("Shopping Cart").WebElement("$3.99").Output CheckPoint("Shoppingcart_subtotal")

Browser("Home").Page("Shopping Cart").Check CheckPoint("Shopping Cart_price_2")

''#Browser("Home").Page("Shopping Cart").WebElement("$3.99").Output CheckPoint("$3.99")

Browser("Home").Page("Shopping Cart").Image("ctl00$uxMNJDefaultContentPlace").FireEvent "onmouseover"

Browser("Home").Page("Shopping Cart").Image("ctl00$uxMNJDefaultContentPlace").Click 66,10
wait(5)

Browser("Home").Page("Edit Shipping Address").Link("Continue").Click
wait(5)

Browser("Home").Page("Order Shipping Method").Link("Continue").Click
wait(5)

这里我想将 wait(_ 替换为某些另一种方法,如 Exist 来提高性能......

任何人都可以帮我解决这个问题......

谢谢, 古杜G

I am facing issues while using Exist method in QTP..As if i use Exist with If else then it is working fine...but if used directly then not working...

Ex:

Browser("Home").Page("Home_2").WebEdit("ctl00$uxMNJDefaultContentPlace").Click
Browser("Home").Page("Home_2").WebEdit("ctl00$uxMNJDefaultContentPlace").Set DataTable("mfgpartnumber", dtGlobalSheet)  ''#Read mfg# from datasheet

Browser("Home").Page("Home_2").Image("ctl00$uxMNJDefaultContentPlace").FireEvent "onmouseover"

Browser("Home").Page("Home_2").Image("ctl00$uxMNJDefaultContentPlace").Click 31,11
wait(15)

Browser("Home").Page("Shopping Cart").WebElement("$3.99").Output CheckPoint("Shoppingcart_subtotal")

Browser("Home").Page("Shopping Cart").Check CheckPoint("Shopping Cart_price_2")

''#Browser("Home").Page("Shopping Cart").WebElement("$3.99").Output CheckPoint("$3.99")

Browser("Home").Page("Shopping Cart").Image("ctl00$uxMNJDefaultContentPlace").FireEvent "onmouseover"

Browser("Home").Page("Shopping Cart").Image("ctl00$uxMNJDefaultContentPlace").Click 66,10
wait(5)

Browser("Home").Page("Edit Shipping Address").Link("Continue").Click
wait(5)

Browser("Home").Page("Order Shipping Method").Link("Continue").Click
wait(5)

Here i want to replace wait(_ to some another method like Exist to improve performance...

Can anybody help me to sort it out..,.

Thanks,
Guddu G

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

多情癖 2024-09-23 01:35:28

@guddu

由于您等待浏览器加载另一个页面,因此请在适用的情况下使用 Browser.Sync。
如果重新加载页面后没有立即出现对象,请使用带参数的 .Exist 方法。
示例:

boolRC = Browser("Home").Page("Shopping Cart").WebElement("$3.99").Exist(15)  

这样,您最多需要 15 秒的时间让对象出现。如果该对象出现得较早,您的脚本就会运行得更快。
如果对象在出现后延迟可用于操作,请使用 WaitProperty 方法,如@katmoon 指出的那样。

最后,您可以使用可自定义的参数来实现自己的同步功能,例如事件(出现/消失等)、超时、要检查的属性...

示例:http://automation-beyond.com/2009/08/20/gui-object-synchronization-custom-function/

谢谢你,
阿尔伯特·加里耶夫
http://automation-beyond.com/

@guddu

Since you wait for the browser to load another page, use Browser.Sync where applicable.
If an object does not appear right after a page is reloaded, use .Exist method with a parameter.
Example:

boolRC = Browser("Home").Page("Shopping Cart").WebElement("$3.99").Exist(15)  

This way, you give up to 15 seconds for an object to appear. If the object appears earlier, your script moves on faster.
If the object becomes available for operating with a delay after it's appeared, use WaitProperty method, as @katmoon pointed out.

Finally, you can implement your own synchronization function with customizable parameters like event (appear/disappear, etc.), time-out, property to check...

Example: http://automation-beyond.com/2009/08/20/gui-object-synchronization-custom-function/

Thank you,
Albert Gareev
http://automation-beyond.com/

街角迷惘 2024-09-23 01:35:28

Wait – 方法用于指示QTP等待执行
过程基于
仅在指定时间但不具有任何条件
例如 Wait 5 (或) Wait(5) '5 Seconds

这种方法不可取。始终使用动态等待来加快执行速度。

WaitProperty – 方法用于指示QTP等待执行
处理直到它
根据指定时间与对象属性值进行匹配。

例如 Browser("欢迎:Mercury Tours").WaitProperty "name" "欢迎:
Mercury Tours” 5000

  1. 属性名称 - “名称”
  2. 属性值 - “欢迎:Mercury Tours”
  3. 5000 - 等待的毫秒数

    调暗 i=0

    我=我+1

    bstatus = browser().exist(1) '“1”表示最多等待 1 秒,然后继续进行

    if i>15 then '这里指定等待时间(我提到了15秒)

    退出
    

    结束如果

    循环直到 bstatus=true

通过提供同步点测试器尝试匹配执行
QTP 和应用程序的速度,因为可能会发生下一个
您正在执行的操作取决于之前的结果和
它还没有生成。
任何对象的默认等待时间为 20 秒,而对象则不是
20 秒内出现可能会导致脚本失败。所以为了避免这样的情况
我们使用同步点的条件

总是使用Waitproperty
不要使用硬编码等待

Exist 方法将始终返回布尔值

Object.existBrowser().page().exist() 这将返回一个布尔值 true or false

blnStatus = Browser().exist()

msg​​box blnstatus '返回 true 或 false

Wait – method is used to instruct the QTP to wait the execution
process based on
the specified time only but not on any condition
E.g. Wait 5 (or) Wait(5) ‘5 Seconds

This method is not advisable.Always use dynamic wait to speed up the execution.

WaitProperty – method is used to instruct QTP to wait the execution
process until it
matches with the object property value based on the specified time.

E.g. Browser("Welcome: Mercury Tours").WaitProperty "name" "Welcome:
Mercury Tours" 5000

  1. property name - "name"
  2. property value - "Welcome: Mercury Tours"
  3. 5000 - number of milli seconds to wait

    Dim i=0
    do
    i=i+1

    bstatus = browser().exist(1) ' "1" means it will wait max 1 sec then it will proceed further

    if i>15 then 'here specify the wait time(i mentioned 15 sec)

    exit do
    

    End if

    loop until bstatus=true

By providing synchronization point tester tries to match the execution
speed of QTP and Application because it may happen that the next
operation that you are performing is depending on previous result and
it is not generated yet.
Default wait time for any object is 20 second and object is not
appearing in 20 second than that may fail script. So to avoid such
condition we use Synchronization Points

Always use Waitproperty
Don't use hardcoded wait

Exist method will always return boolean value

Object.exist or Browser().page().exist() this will return a boolean value say true or false

blnStatus = Browser().exist()

msgbox blnstatus 'return true or false

姜生凉生 2024-09-23 01:35:28

您好,这是我正在使用的一个简单功能,而不是等待和禁用属性,我认为它可能会有所帮助..谢谢您..

Set NavigationTab = Browser ().Page().WebElement()
PerformWait ( 10 , 10 , NavigationTab )


Function PerformWait ( intDisableTime , intDelay , object )

if CheckExist ( intDelay , object ) Then

if ValidateDisabled ( object , intDisableTime ) Then

    object.Sync
    Reporter.ReportEvent 0 , "Element is ready to use" , "The  specified element is ready to use" & Date & Time


  Else

   Reporter.ReportEvent 3 , "Object Disabled." , "Object remains disabled after specified time : " & refDisableTime & Date & Time   

End If

Else

Reporter.ReportEvent 3 , "Element not present." , "The specified element not present : " & Date & Time

End If

End Function

Function CheckExist ( intDelay , object )

object.RefreshObject

' -- validating the object is exist or not.
If object.Exist ( intDelay ) Then

 CheckExist = True

Else

 CheckExist = False

 End If

End Function


Function ValidateDisabled ( object , intDisableTime )


For Iterator = 1 To intDisableTime Step 1

' -- validating the object is disabled or not.
If object.GetROProperty ( "disabled" ) = 1 Then

    wait 1  
    ValidateDisabled = False

Else

    ValidateDisabled = True
    Exit For    

End If

Iterator = Iterator + 1
Next

End Function

Hi This Is a simple function I'm using instead of wait and disabled property i think it may help.. Thank You..

Set NavigationTab = Browser ().Page().WebElement()
PerformWait ( 10 , 10 , NavigationTab )


Function PerformWait ( intDisableTime , intDelay , object )

if CheckExist ( intDelay , object ) Then

if ValidateDisabled ( object , intDisableTime ) Then

    object.Sync
    Reporter.ReportEvent 0 , "Element is ready to use" , "The  specified element is ready to use" & Date & Time


  Else

   Reporter.ReportEvent 3 , "Object Disabled." , "Object remains disabled after specified time : " & refDisableTime & Date & Time   

End If

Else

Reporter.ReportEvent 3 , "Element not present." , "The specified element not present : " & Date & Time

End If

End Function

Function CheckExist ( intDelay , object )

object.RefreshObject

' -- validating the object is exist or not.
If object.Exist ( intDelay ) Then

 CheckExist = True

Else

 CheckExist = False

 End If

End Function


Function ValidateDisabled ( object , intDisableTime )


For Iterator = 1 To intDisableTime Step 1

' -- validating the object is disabled or not.
If object.GetROProperty ( "disabled" ) = 1 Then

    wait 1  
    ValidateDisabled = False

Else

    ValidateDisabled = True
    Exit For    

End If

Iterator = Iterator + 1
Next

End Function
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文