【问题标题】:Scrolling does not work on webdriver.io on the web滚动在 web 上的 webdriver.io 上不起作用
【发布时间】:2017-04-18 20:52:41
【问题描述】:

我无法使用 webdriver.io 向下滚动。没有收到任何错误消息,只是没有滚动。我尝试了 Webdrver.io 文档中的不同解决方案:

it('should demonstrate the scroll command', function () {
    var elem = $('#myElement');
    // scroll to specific element
    elem.scroll();
    // scroll to specific element with offset
    // scroll offset will be added to elements position
    elem.scroll(100, 100);
    // scroll to specific x and y position
    browser.scroll(0, 250);
});

它们都不起作用,有什么建议吗?

【问题讨论】:

  • 你可以尝试Actions类的move_to_element(element)来模拟滚动。

标签: selenium selenium-webdriver webdriver-io webautomation


【解决方案1】:
// Create instance of Javascript executor

JavascriptExecutor je = (JavascriptExecutor) driver;

//Identify the WebElement which will appear after scrolling down

WebElement e=driver.findElement(By.xpath("//*[@id='content-5']"));
je.executeScript("arguments[0].scrollIntoView(true);",e);

【讨论】:

  • 它不适用于 java。标题说它的 Webdriver.IO 是 JS 框架
【解决方案2】:

我正在使用 v4 并且 browser.scroll() 对我也不起作用。

我改为使用 Actions -> moveToObject 并成功滚动到元素。

这是我的代码的样子。

browser.moveToObject('#id-of-my-element');

【讨论】:

  • 虽然更好的解决方案是升级到 v5!
【解决方案3】:

您可以使用Actions 类的moveToElement() 方法将鼠标移动到指定元素。

例如:

WebElement element= driver.findElement(By.name("Name"));

Actions builder = new Actions(driver);

builder.moveToElement(element).build().perform();

您还可以使用MoveToElement() 将鼠标移动到指定元素左上角的指定偏移量。 语法:MoveToElement(IWebElement, Int32, Int32);

Actions.htm

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    • 1970-01-01
    相关资源
    最近更新 更多