2016-06-29 73 views
0

我正在測試一個gwt webapp。在我的硒測試儘可能動態的過程中,我碰到了一堵牆。該元素來自一個頁面,它有一個彈出窗口,它也有一個彈出窗口,其中包含該元素的下拉菜單。問題是該元素不在視圖中,因此我無法單擊該元素。Selenium將元素滾動到視圖

不是要滾動身體頁

我需要的元素滾動到視圖,而一些如何與XPath將這一發現元素: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>

我相信問題是GWT使用iframe中。

回答

0

使用Action類:

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

沒有工作了。我相信這與gwt做事的方式有關。它適用於其他應用程序而不是gwt應用程序。 – Amd046