如何在Selenium WebDriver中处理多个scrollintoview

时间:2019-03-05 12:58:50

标签: selenium-webdriver js-scrollintoview

我需要滚动页面到特定的div,其中包含特定的单词“ Load more”,该单词在多个div中具有多个文本。这是我的代码

List<WebElement> Loadmore = driver.findElements(By.xpath("//div[contains(text(), 'Load more')]"));
    for(int i=0;i<Loadmore.size();i++)
    {
        String Loadmoreid = Loadmore.get(i).getAttribute("id");
        WebElement Loadmoretxt = driver.findElement(By.xpath("//div[contains(@id, '"+Loadmoreid+"')]"));
        JavascriptExecutor js = (JavascriptExecutor) driver;
        js.executeScript("arguments[0].scrollIntoView(true);", Loadmoretxt);
        WebElement Loadmoreweb = driver.findElement(By.id(Loadmoreid));
        Actions action = new Actions(driver);
        action.moveToElement(Loadmoreweb).click().perform();
    }

1 个答案:

答案 0 :(得分:0)

您尝试过这个

Actions action = new Actions(Loadmoretxt);
action.moveToElement(target);
action.perform();