2013-08-30 57 views
0

我在使用IE10中的Webdriver方法moveto時遇到問題。 我打算做的是滾動一個當前不可見的項目,它位於溢出的div中。使用Selenium在IE10中移動元素

HTML例如:

<div id="container" style="height: 500px; width: 200px; overflow: auto;"> 
    <div id="first" style="height: 1000px; width: 200px; background-color: red;"></div> 
    <div id="second" style="height: 200px; width: 200px; background-color: green;"></div> 
</div> 

在上述我想的#second元件上使用通過MoveTo的例子。這在Firefox中運行得很好,但IE10中沒有。我使用WebDriverJs和Selenium 2.33.0。

回答

0

使用下面的代碼滾動到元素

JavascriptExecutor jse = (JavascriptExecutor)driver; 
jse.executeScript("window.scrollBy(0,2000)", ""); 

向下滾動到元素。

向上滾動做

JavascriptExecutor jse = (JavascriptExecutor)driver; 
jse.executeScript("window.scrollBy(2000,0)", ""); 
+0

我認爲這太,但我寧願做沒有的JavaScript。它不應該與moveto一起工作嗎? – jonte