简体   繁体   English

如何等待元素在Ranorex上可见?

[英]How to wait an element is visible on Ranorex?

In Ranorex, I found how to wait for the existence of an element, but I don't find how to wait the element is visible. 在Ranorex中,我找到了如何等待元素存在的方法,但是我没有找到如何等待元素可见的方法。

在此处输入图片说明

I want to do the same thing, but I want to wait until the element is visible. 我想做同样的事情,但是我想等到元素可见。 Unfortunately, I just see Exist and Not Exist as possible values for the WaitFor statement. 不幸的是,我只是将“ Exist和“ Not Exist视为WaitFor语句的可能值。 And in my case, the test is unreliable, cause the click is sometimes launched in spite of the existence of the element, but is still not displayed 在我的情况下,该测试是不可靠的,因为尽管该元素存在,但有时还是会启动点击,但仍然无法显示

Do you know how to do this please? 你知道怎么做吗?

您可以在回购路径[@visible='true']添加此元素,并使用WaitForExists

repo.elementInfo.WaitForExists(SearchTimeOut)

You can use the Visible property to wait for the element: 您可以使用Visible属性等待元素:

DateTime start = DateTime.Now;

while (Repository.Element.Visible)
{               
    Delay.Seconds(1);

    if(System.DateTime.Now.Subtract(start).TotalSeconds > MaxWaitTime)
    {                   
        Validate.Fail("");
    }
}

For Web elements, it is difficult to know whether an item exists, is visible, etc. 对于Web元素,很难知道某项是否存在,是否可见等。

I achieved reliability using the DOM page location and width by comparing them to, in my example, a sliding menu position and width, as follows: 在我的示例中,通过将DOM页面的位置和宽度与滑动菜单的位置和宽度进行比较,我获得了可靠性,如下所示:

    Public Function IsMenuVisible() As Boolean
        Dim menuVisible As Boolean

        'Get page position and width
        Dim pageXPosition As Integer = repo.WebPage.Self.Element.ScreenLocation.X
        Dim pageWidth As Integer = repo.WebPage.Self.Element.ScreenRectangle.Width
        'Get configuration menu position and width
        Dim menuXPosition As Integer = repo.WebPage.Menu.Self.Element.ScreenLocation.X
        Dim menuWidth As Integer = repo.WebPage.Menu.Self.Element.ScreenRectangle.Width

        'If menu top right location is >= web page size (out of screen)
        If menuXPosition + menuWidth > pageXPosition + pageWidth Then
            Report.Info(String.Format("Configuration menu is hidden (menuXPositon = {0}, pageXPosition = {1}, pageWidth = {2}, menuWidth = {3}).", menuXPosition, pageXPosition, pageWidth, menuWidth))
            menuVisible = False
        Else
            Report.Info("Configuration menu is currently visible.")
            menuVisible = True
        End If

        Return menuVisible
    End Function

In my example, the menu is located on the right of the page. 在我的示例中,菜单位于页面的右侧。 Please modify it according to your needs. 请根据您的需要进行修改。

Then, do simple user code to loop a number of times to wait for the menu to appear as follows: 然后,执行简单的用户代码循环多次以等待菜单出现,如下所示:

        Public Sub WaitForMenuToAppear()
        Dim retries As Integer = WaitForMenuToAppearRetries
        While Not IsMenuVisible() AndAlso retries > 0
            retries -= 1
            Report.Info(String.Format("Waiting for configuration menu to be visible ({0}).", retries))
            Delay.Duration(1000)
        End While

        If Not IsMenuVisible() Then
            Throw New RanorexException(String.Format("Menu did not appear within '{0}' seconds.", WaitForMenuToAppearRetries))
        Else
            Report.Info("Menu is visible.")
        End If
    End Sub

I had to do this since the sliding is always visible. 我必须这样做,因为滑动总是可见的。 Using the highlight function of Ranorex Spy, the red rectangle is drawn outside the viewing area of the Web page. 使用Ranorex Spy的突出显示功能,将红色矩形绘制在网页查看区域之外。

I leave to you to complete the example. 我请您完成示例。

Hope this helps… 希望这可以帮助…

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

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