Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I am writing a program to run videos listed on my site for testing purpose and here what I need is to run videos in different tabs of the same browser window.

I have hundred video urls in the List<string> videoLinks = getVideoUrls();
and now what I need is to execute these videos 5 at a time.

C#
ChromeDriver driver = new ChromeDriver();
            driver.Navigate().GoToUrl("https://www.withoutabox.com" + videoLink);


If I go the above way then for all videos I will have to create a new ChromeDriver object. I want to use single chrome browser object.

I have tried this
C#
IWebElement body = driver.FindElement(By.TagName("body"));
               body.SendKeys(Keys.Control + "t");



it only adds a new tab but not open a link there.
Please let me know how should I go around it. I have googled but couldn't find my solution so thought to ask for help from you geeks.

I would appreciate your response.
Thanks
Posted
Updated 5-May-21 11:24am

Actions action = new Actions(_driver);
action.KeyDown(Keys.Control).MoveToElement(body).Click().Perform();

This will open IwebElement body in new tab.
 
Share this answer
 
I would add that this piece of code:

Actions action = new Actions(_driver);
action.KeyDown(Keys.Control).MoveToElement(body).Click().Perform();


will not release CTRL key in the keyboard what can cause openning new tab in same window if this piece of code is running in a loop.

So right version is:

Actions action = new Actions(_driver);
action.KeyDown(Keys.Control).MoveToElement(body).Click().KeyUp(Keys.Control).Perform();
 
Share this answer
 
v2
var driver = new ChromeDriver();
driver.FindElement(By.CssSelector("Body")).SendKeys(Keys.Control + "t");
driver.SwitchTo().Window(driver.WindowHandles.Last());
driver.Navigate().GoToUrl("http://www.google.com");
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900