2017-04-21 38 views
1

如何使用Selenium Webdriver在Firefox上处理嵌套滚动条?我试图自动化的功能是在向下滚动整个框架时,下一个按钮被启用。我试过JavaScript执行程序,但它滚动主页,而不是在div内。我也尝试过使用操作,请参阅下面我的代码:在网页上滚动div而不滚动Selenium Webdriver中的主页

WebElement snapshot_list = driver.findElement(By.id("snapshots-list")); 
Actions scrolldown = new Actions(driver); 

scrolldown.moveToElement(snapshot_list).build().perform(); 
snapshot_list.click(); 

scrolldown.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform(); 

它没有任何错误造成的,随着时间的流逝TestNG中,但它只是跳过scrolldown.keyDown部分出现在测试用例。我究竟做错了什么?任何帮助将不胜感激。

+0

为什么你需要'scrolldown.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform(); '一部分? – kushal

回答

0

你已经提到你尝试过Javascript执行程序,但是不知道你尝试了什么。如果您已经在下面尝试过,请忽略它们。

(((JavascriptExecutor)driver)).executeScript("document.getElementById('snapshots-list').scrollIntoView({ 
    behavior: 'smooth' 
});"); 

(((JavascriptExecutor)driver)).executeScript("document.getElementById('snapshots-list').scrollIntoView(true);"); 

(((JavascriptExecutor)driver)).executeScript("jQuery(\"snapshots-list\").mouseover();"); 

或低于

WebElement snapshot_list = driver.findElement(By.id("snapshots-list")); 
Actions scrolldown = new Actions(driver); 

scrolldown.moveToElement(snapshot_list).click().build().perform(); 
+0

谢谢!我通过Actions进行了一些调整,并且工作。 –

0

问题解决了所提到移动元素后,立即点击!我实现它通过操作,我关注的元素结构框架和while循环中添加以下条件:

Actions action = new Actions(driver); 
action.moveToElement(FirstSnapshot).build().perform(); 
FirstSnapshot.click(); 

while(Nextbutton.isEnabled()== false) 
     { 
     action.keyDown(Keys.CONTROL).sendKeys(Keys.DOWN).perform(); 
     } 
System.out.println("Button is enabled"); 
1

下面的代码为我工作滚动div-

WebElement eleAssistanceInput = driver.findElement(By.id("abc")); 
//the above element will be visible after scrolling down the div.      
         ((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", eleAssistanceInput); 

         eleAssistanceInput.click();