How to scroll in New tab in selenium

后端 未结 2 1181
广开言路
广开言路 2021-01-24 04:06

I opened a new tab by clicking something in selenium in c #. I want to scroll after changing to a new tab, but I get a timeout error.

I get a timeout message and no scro

2条回答
  •  -上瘾入骨i
    2021-01-24 05:00

    you can do this by two steps, move to the new tab and do the scroll there.

    ArrayList AllTabs = new ArrayList (driver.getWindowHandles()); 
    driver.switchTo().window(AllTabs.get(1));
    JavascriptExecutor js = (JavascriptExecutor) driver;
    js.executeScript("window.scrollBy(0 , window.innerHeight)");
    

    And you can close the tab after you finish.

提交回复
热议问题