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
Please use the below code it will work fine
//Open link in new tab
Actions act = new Actions(driver);
act.KeyDown(Keys.Control).MoveToElement(elementToopenInNewTab).Click().Perform();
// Switch to new tab
driver.SwitchTo().Window(driver.WindowHandles.Last());
//Scroll down in new tab
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("window.scrollTo(0, document.body.scrollHeight)");
//Move to first tab again
driver.SwitchTo().Window(driver.WindowHandles.First());
you can do this by two steps,
move to the new tab
and do the scroll
there.
ArrayList<String> AllTabs = new ArrayList<String> (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.