0

下面是代码:

JavascriptExecutor jse = (JavascriptExecutor)driver;
WebElement blueray = driver.findElement(By.xpath("Xpath ID")]"));
jse.executeScript("scroll(0,250)", blueray);

以下是错误:

The method executeScript(String, Object[]) in the type JavascriptExecutor is not applicable for the arguments (String, WebElement)
4

2 回答 2

0

有关您的用例的更多详细信息将有助于我们构建规范的答案。

如果您的用包含 DOM 文档scroll()的窗口,那么除了使用以下任一窗口方法之外,没有更好的方法:

如果您的用scroll()一个元素,那么没有比使用元素方法更好的方法了:

  • Element.scrollIntoView()

    JavascriptExecutor jse = (JavascriptExecutor)driver;
    WebElement blueray = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("Xpath ID")));
    jse.executeScript("arguments[0].scrollIntoView();", blueray);
    

您可以在scrollIntoView() 方法实现中找到相关的详细讨论


参考

您可以在以下位置找到一些相关的讨论:

于 2020-05-23T09:30:30.260 回答
0

我们不清楚您到底要滚动什么,但如果您尝试滚动窗口,请使用以下代码

jse.executeScript("window.scrollBy(0,250)");

如果您想查看页面中的 blueRay 网页元素,您需要使用以下代码

jse.executeScript("arguments[0].scrollIntoView()", blueRay);

如果这没有帮助,请用您面临的确切问题更新您的问题并详细说明该问题,以便我们可以帮助您快速解决此问题,我的朋友:)

于 2020-05-23T05:53:33.307 回答