1

我正在打开此页面http://www.ebay.com/itm/Apple-iPhone-5-16GB-White-Silver-Factory-Unlocked-/151097083750?pt=Cell_Phones&hash=item232e168766

并检查蓝丝带是否可见,如图像中所述在此处输入图像描述

这是我的测试

<tr>
    <td>open</td>
    <td>/itm/Apple-iPhone-5-16GB-White-Silver-Factory-Unlocked-/151097083750?pt=Cell_Phones&amp;hash=item232e168766</td>
    <td></td>
</tr>
<tr>
    <td>isVisible</td>
    <td>//div[@class='vi-notify-msg']</td>
    <td></td>
</tr>

并期待它失败但令人惊讶的是它每次都通过......我在这里错过了什么?

编辑:

我预计测试会失败,因为功能区在页面加载后需要一些时间才能出现,并且isVisible在功能区可见之前执行的命令..所以它应该失败对吗?

4

1 回答 1

4

如果您查看 HTML,则该元素在页面加载时就在那里。它只是在页面加载完成后淡入淡出,但从 HTML 的角度来看,它在页面加载的整个过程中都是“可见的”:

加载页面时:

<div id="vi_notification" class="vi-notify-cmp" style="top:25%;">
    <div class="vi-notify-container vi-notify-shadow">
        <div class="vi-notify-icon vi-notify-icon-img"></div>
        <div class="vi-notify-msg">28 people are viewing this item per hour.</div>
        <div class="vi-notify-close">
            <button id="vi_notification_cls_btn" class="vi-notify-   close-btn">x</button>
        </div>
    </div>
</div>

只有在它淡出之后,样式才会更改为display:none

<div id="vi_notification" class="vi-notify-cmp" style="top: 25%; left: 10px; display: none;">
    <div class="vi-notify-container vi-notify-shadow">
        <div class="vi-notify-icon vi-notify-icon-img"></div>
    <div class="vi-notify-msg">28 people are viewing this item per hour.</div>
    <div class="vi-notify-close">
            <button id="vi_notification_cls_btn" class="vi-notify-close-btn">x</button>
        </div>
    </div>
</div>

如果您使用 Chrome 开发人员工具栏在加载元素时查看元素,您会看到它“可见”的位置,但样式会更新以缓慢淡入,以便我们的肉眼可以看到它。

这意味着当页面正在加载/加载时,元素将按显示返回。在它淡出之后,我希望显示返回 false,因为父 div 上的样式已更改为 display:none。

于 2013-08-07T20:09:44.643 回答