How to scroll in New tab in selenium

后端 未结 2 1182
广开言路
广开言路 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条回答
  •  一整个雨季
    2021-01-24 04:41

    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());
    

提交回复
热议问题