How to open new tab of Chrome using Selenium in vb.net

34 views Asked by At

I have tried to send keys but it's not working.

IWebElement body = driver.FindElement(By.TagName("body"))
body.SendKeys(Keys.Control + "T")

I also tried action class:

Actions act = new Actions(driver);
act.keyDown(Keys.CONTROL).sendKeys("t").keyUp(Keys.CONTROL).build().perform();
2

There are 2 answers

0
Suresh Kumawat On

You can use the following for vb.net

Dim js As IJavaScriptExecutor = TryCast(driver, IJavaScriptExecutor)    
js.ExecuteScript("window.open()")    
driver.SwitchTo().Window(driver.WindowHandles.Last())
0
Sahil On

try this

from selenium import webdriver
import time
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(ChromeDriverManager().install())
driver.get('https://www.w3schools.com/c/')
driver.execute_script("window.open('');")
driver.switch_to.window(driver.window_handles[1]) 
driver.get("https://www.lenskart.com/") 
driver.close()