Selenium滚动元素到视图中

时间:2016-06-29 20:16:13

标签: selenium xpath gwt scroll move

我正在测试gwt webapp。在使我的硒测试尽可能动态的过程中,我碰到了一堵墙。该元素来自一个页面,该页面有一个弹出窗口,其中还有一个弹出窗口,其中包含一个包含该元素的下拉列表。问题是该元素不在视图中,因此我无法单击该元素。

不试图滚动页面正文

我需要将元素滚动到视图中,而有些如何通过xpath合并此find元素:driver.findElement(By.xpath("//*[contains(text(), 'NO')]")).an_action();

使用"包含"在使这项测试充满活力方面非常重要。

这是我试图控制的部分的HTML:



<div id="x-auto-908" class="x-combo-list x-ignore x-component x-border " role="presentation" style="border-width: 1px; z-index: 1565; visibility: visible; height: 298px; width: 104px; left: 670px; top: 94px;">
<div id="x-auto-740" class=" x-view x-combo-list-inner x-component x-unselectable" tabindex="0" hidefocus="true" style="overflow-x: hidden; padding: 0px; border-width: 0px; height: 298px; width: 104px;" unselectable="on">
<div class="x-combo-list-item " role="listitem">--</div>
<div class="x-combo-list-item" role="listitem">AL</div>
<div class="x-combo-list-item " role="listitem">AR</div>
<div class="x-combo-list-item" role="listitem">CO</div>
<div class="x-combo-list-item" role="listitem">FL</div>
<div class="x-combo-list-item " role="listitem">FL</div>
<div class="x-combo-list-item " role="listitem">GA</div>
<div class="x-combo-list-item " role="listitem">HH</div>
<div class="x-combo-list-item" role="listitem">IA</div>
<div class="x-combo-list-item " role="listitem">ID</div>
<div class="x-combo-list-item " role="listitem">IL</div>
<div class="x-combo-list-item " role="listitem">IN</div>
<div class="x-combo-list-item x-view-highlightrow x-combo-selected" role="listitem">KK</div>
<div class="x-combo-list-item" role="listitem">KS</div>
<div class="x-combo-list-item" role="listitem">LA</div>
<div class="x-combo-list-item" role="listitem">LL</div>
<div class="x-combo-list-item" role="listitem">MI</div>
<div class="x-combo-list-item" role="listitem">MM</div>
<div class="x-combo-list-item" role="listitem">MN</div>
<div class="x-combo-list-item" role="listitem">MO</div>
<div class="x-combo-list-item" role="listitem">MS</div>
<div class="x-combo-list-item" role="listitem">MT</div>
<div class="x-combo-list-item" role="listitem">NC</div>
<div class="x-combo-list-item" role="listitem">NE</div>
<div class="x-combo-list-item" role="listitem">NJ</div>
<div class="x-combo-list-item" role="listitem">NM</div>
<div class="x-combo-list-item" role="listitem">NO</div>
<div class="x-combo-list-item" role="listitem">NV</div>
<div class="x-combo-list-item " role="listitem">OH</div>
<div class="x-combo-list-item" role="listitem">OK</div>
<div class="x-combo-list-item" role="listitem">OR</div>
<div class="x-combo-list-item" role="listitem">PA</div>
<div class="x-combo-list-item" role="listitem">SC</div>
<div class="x-combo-list-item" role="listitem">TN</div>
<div class="x-combo-list-item" role="listitem">TX</div>
<div class="x-combo-list-item" role="listitem">VA</div>
<div class="x-combo-list-item" role="listitem">WA</div>
<div class="x-combo-list-item" role="listitem">WI</div>
<div class="x-combo-list-item" role="listitem">WW</div>
<div class="x-combo-list-item" role="listitem">WY</div>
<div class="x-combo-list-item" role="listitem">ZZ</div>
</div>
&#13;
&#13;
&#13;

我认为问题是gwt使用iframe。

1 个答案:

答案 0 :(得分:0)

使用Action类:

Actions actions = new Actions(getDriver());
actions.moveToElement(webElement);