【问题标题】:Scroll down automatically to an xpath element自动向下滚动到 xpath 元素
【发布时间】:2019-03-08 16:56:47
【问题描述】:

我已经看到这个代码去一个特定的元素。

    WebElement element = driver.findElement(By.xpath("Value"));
    Coordinates coordinate = ((Locatable)element).getCoordinates(); 
    coordinate.onPage(); 
    coordinate.inViewPort();

我试图在我的代码中实现这一点,但是当驱动程序中出现一条消息时,如图所示。难道我做错了什么? 也许我必须导入一个包或创建一个实例?

感谢您的帮助。

【问题讨论】:

  • 将驱动程序作为参数添加到函数中:public void func(WebDriver driver)

标签: java selenium selenium-webdriver cucumber-serenity


【解决方案1】:

尝试使用 JavaScript:

((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(false);", element);

【讨论】:

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