如何在Selenium Webdriver中处理多个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();
    }

您是否尝试过此

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

相关内容

  • 没有找到相关文章

最新更新