0

我需要将页面滚动到包含特定单词“加载更多”的特定 div,该单词在多个 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();
    }
4

1 回答 1

0

你试过这个吗

Actions action = new Actions(Loadmoretxt);
action.moveToElement(target);
action.perform();
于 2019-03-05T13:24:00.810 回答