2011-12-08 103 views
6

我正在使用FirefoxDriver webdriver。在Firefox窗口中加載的頁面是一個大頁面,我想使用硒滾動該頁面。如何使用硒滾動頁面

我想知道如何做到這一點。

謝謝。

+0

我假設你想要使用Selenium API,下面是使用Selenium API滾動頁面的鏈接。 [滾動頁面](http://testerinyou.blogspot.com/2011/05/how-to-scroll-page.html) –

+0

您應該**將注意力集中到所需的項目上,硒2將負責找到它。看看這個帖子http://stackoverflow.com/questions/3401343/scroll-element-into-view-with-selenium –

回答

10

如果你想使用硒webdriver的Firefox窗口上滾動,方式之一就是在Java代碼中使用JavaScript中,javeScript代碼向下滾動如下:

WebDriver driver = new FirefoxDriver(); 
JavascriptExecutor js = (JavascriptExecutor)driver; 
js.executeScript("window.scrollTo(0,Math.max(document.documentElement.scrollHeight," + "document.body.scrollHeight,document.documentElement.clientHeight));"); 
0
page.driver.browser.mouse.move_to(find("element").native,100,100) 
0

使用此代碼滾動一頁向下

Actions actions = new Actions(driver); 
actions.sendKeys(Keys.BACK_SPACE).perform(); 
+1

你確定這是發送的正確密鑰?它似乎是一個'退格鍵'按鍵,它不會滾動頁面。 –

+0

Page Down鍵或許? –

0

我認爲你應該做這樣的事情

driver.execute_script("window.scrollTo(0, document.body.scrollHeight);") 

祝你好運。