如何使用Selenium WebDriver在DIV内滚动

时间:2017-07-27 06:23:11

标签: selenium scroll webdriver

enter image description here

在DIV中,一次只显示五个元素,HTML代码也只有五个tgas,如下所示。

<div class="filter-item-wrapper" style="width: 193px; height: 150.5px; overflow: hidden;">
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 322px; display: block; left: 0px;">
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 322px; display: block; left: 0px;">
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 322px; display: block; left: 0px;">
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 322px; display: block; left: 0px;">
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 322px; display: block; left: 0px;">
</div>

在向下滚动时,只会刷新五个元素数据。

我尝试使用以下代码。

// Create instance of Javascript executor
JavascriptExecutor je = (JavascriptExecutor) driver;
//Identify the WebElement which will appear after scrolling down
WebElement element = driver.findElement(By.tagName("...."));
// now execute query which actually will scroll until that element is not appeared on page.
je.executeScript("arguments[0].scrollIntoView(true);",element);

但是这对我没有帮助,因为每次最后一个元素相同时,元素内的数据才会被刷新。

请帮我看看如何滚动上面的列表。

滚动前

<div class="filter-item-wrapper" style="width: 193px; height: 150.5px; overflow: hidden;">
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 322px;">
<input class="filter-item-input" value="(Blanks)" type="checkbox">
<span class="filter-item-text">(Blanks)</span>
</div>
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 322px;">
<input class="filter-item-input" value="BMC Remedy Migrator 3.0" type="checkbox">
<span class="filter-item-text">BMC Remedy Migrator 3.0</span>
</div>
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 322px;">
<input class="filter-item-input" value="Bottomline Create!form Director 6.1" type="checkbox">
<span class="filter-item-text">Bottomline Create!form Director 6.1</span>
</div>
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 322px;">
<input class="filter-item-input" value="Bottomline Create!form Director 6.2" type="checkbox">
<span class="filter-item-text">Bottomline Create!form Director 6.2</span>
</div>
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 322px;">
<input class="filter-item-input" value="Cisco Application Networking Manager (ANM) 4.1" type="checkbox">
<span class="filter-item-text">Cisco Application Networking Manager (ANM) 4.1</span>
</div>
</div>

滚动后

<div class="filter-item-wrapper" style="width: 193px; height: 150.5px; overflow: hidden;">
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 344px;">
<input class="filter-item-input" value="Sage Peachtree Premium Accounting 12.0 SR2 (2005)" type="checkbox">
<span class="filter-item-text">Sage Peachtree Premium Accounting 12.0 SR2 (2005)</span>
</div>
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 344px;">
<input class="filter-item-input" value="Sage Peachtree Premium Accounting 12.0 SR3 (2005)" type="checkbox">
<span class="filter-item-text">Sage Peachtree Premium Accounting 12.0 SR3 (2005)</span>
</div>
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 344px;">
<input class="filter-item-input" value="Sage Peachtree Premium Accounting 13.0 (2006)" type="checkbox">
<span class="filter-item-text">Sage Peachtree Premium Accounting 13.0 (2006)</span>
</div>
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 344px;">
<input class="filter-item-input" value="Sage Peachtree Premium Accounting 13.0 SR1 (2006)" type="checkbox">
<span class="filter-item-text">Sage Peachtree Premium Accounting 13.0 SR1 (2006)</span>
</div>
<div class="filter-item" style="padding-top: 4.625px; padding-bottom: 4.625px; border-width: 1px; margin: 2px; height: 20px; box-sizing: content-box; width: 344px;">
<input class="filter-item-input" value="Sage Peachtree Premium Accounting 13.0 SR2 (2006)" type="checkbox">
<span class="filter-item-text">Sage Peachtree Premium Accounting 13.0 SR2 (2006)</span>
</div>
</div>

0 个答案:

没有答案