我需要向下滚动,直到在电子商务网站使用硒webdriver完成搜索结果

I need to scroll down until the search result complete in e-commerce website using selenium webdriver

本文关键字:商务网站 webdriver 搜索结果 滚动      更新时间:2023-09-26

我想向下滚动页面底部

预期的步骤:

  1. 打开申请网站(www.jabong.com)
  2. 我在搜索框中搜索男士手表
  3. 页面将给出搜索结果。这里我需要向下滚动页面,直到页面完成搜索结果。
我希望你能理解我的问题。我尝试了下面的代码滚动使用硒
WebElement bottomButton = driver.findElement(By.xpath("//*[@id='catalog-product']/footer/button"));
        WebDriverWait wait = new WebDriverWait(driver, 15);
        do{
            wait.until(ExpectedConditions.visibilityOf(bottomButton));
            JavascriptExecutor js = (JavascriptExecutor) driver;
            js.executeScript("window.scrollBy(0,document.body.scrollHeight);");
            bottomButton.click();
        }while(!bottomButton.isDisplayed());

这个适合我:

js.executeScript("scroll(0,document.body.scrollHeight);");

我记得我试过窗户。scrollBy,它也不工作,不知道为什么…