Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium:使用Actions类进行水平滚动_Selenium_Selenium Webdriver_Scrollbar_Action_Mcustomscrollbar - Fatal编程技术网

Selenium:使用Actions类进行水平滚动

Selenium:使用Actions类进行水平滚动,selenium,selenium-webdriver,scrollbar,action,mcustomscrollbar,Selenium,Selenium Webdriver,Scrollbar,Action,Mcustomscrollbar,我已经尝试过通过Selenium操作和Javascript Executor访问我网页上的这个自定义滚动条。滚动条仅滚动500像素,而实际上我希望它滚动整个宽度。感谢您的帮助。下面是我当前的代码片段: WebElement slider = element("slider_div"); WebElement scrollbar = element("scrollbar"); int w = slider.getSize().getWidth(); Actions move = new A

我已经尝试过通过Selenium操作和Javascript Executor访问我网页上的这个自定义滚动条。滚动条仅滚动500像素,而实际上我希望它滚动整个宽度。感谢您的帮助。下面是我当前的代码片段:

 WebElement slider = element("slider_div");
 WebElement scrollbar = element("scrollbar");
 int w = slider.getSize().getWidth();
 Actions move = new Actions(driver);
 move.dragAndDropBy(e, offset, 0).build() .perform();
我也尝试过以下解决方案,但仍然没有成功:

WebElement slider = element("slider_div");
WebElement scrollbar = element("scrollbar");
int w = slider.getSize().getWidth();
clickByJavascript(slider);
Actions action = new Actions(driver); 
action.sendKeys(Keys.RIGHT).build().perform();`

提前感谢

我已经在下面指定的站点上测试了您的场景,包括水平和垂直滚动

测试URL«
https://trello.com/b/LakLkQBW/jsfiddle-roadmap

元素内部垂直滚动«

  • Selenium java:

    WebElement=driver.findElement(By.xpath(“//div[@id='board']]/div[1]/div[1]/div[2]”);
    对于(int i=0;i<5;i++){
    jse.executeScript(“参数[0].scrollTop+=200;”,元素);
    }
    
  • javascript
    |
    jquery:

    var objDiv=$x(“//div[@id='board']/div[1]/div[1]/div[2]”[0];
    console.log(objDiv);
    objDiv.scrollTop+=100;
    //objDiv.scrollTop=objDiv.scrollHeight;
    
元素内部水平滚动«

  • Java操作类

    WebElement horizontalbar=driver.findElement(By.id(“board”));
    动作动作=新动作(驱动);
    Actions moveToElement=action.moveToElement(水平栏);
    对于(int i=0;i<5;i++){
    moveToElement.sendKeys(key.RIGHT).build().perform();
    }
    
滚动直到元素进入视图

  • javascript

    public void滚动到元素(字符串id){
    WebElement=driver.findElement(By.id(id));
    executeScript(“参数[0].scrollIntoView(true);”,元素);
    }
    
滚动到页面末尾

public void scrollPage()引发InterruptedException{
驱动程序。获取(“https://stackoverflow.com/q/33094727/5081877");
动作动作=新动作(驱动);
WebElement=driver.findElement(By.xpath(“//body”);
Actions scrollDown=Actions.moveToElement(元素);
scrollDown.keyDown(Keys.CONTROL).sendKeys(Keys.END).build().perform();
//executeScript(“window.scrollTo(0,document.body.scrollHeight)”;
睡眠(1000*4);
/*Actions scrollUP=Actions.moveToElement(元素);
scrollUP.keyDown(Keys.CONTROL).sendKeys(Keys.HOME).build().perform()*/
executeScript(“window.scrollTo(0,-document.body.scrollHeight)”;
滚动至元素(“应答-3314237”);
}
对于javascript,您可以使用其中任何一种

window.scrollBy(0800);
scrollTo(0,-document.body.scrollHeight);
滚动(0,-文档.正文.滚动高度);
@看


使用以下行从左向右滚动

((JavascriptExecutor) driver).executeScript("window.scrollBy(500000, 0)");
要从右向左滚动,请使用以下行:

((JavascriptExecutor) driver).executeScript("window.scrollBy(-500000, 0)");

这将完全向左或向右滚动,因为(50000)是覆盖页面的一个非常大的值

什么是
WebElement slider=element(“slider_div”)
WebElement滚动条=元素(“滚动条”)精确引用?Hi Debanjan,“slider”指滚动div,“scrollbar”指滚动条元素。让我将HTML粘贴到下面:你能提供更多与HTML页面相关的信息吗?你的问题与
幻灯片元素或滚动页面|元素相关
我的问题与滚动页面|元素相关。它是div中的一个自定义滚动条,您可以共享任何示例页面来尝试元素水平滚动。这是你的问题吗。