python – How do you execute the “ctrl” + “t” shortcut in a chrome browser using Selenium

I am trying to use shortcuts on the open browser using Selenium but nothing happends. I have tried a
few different methods below:

# Initialize the Chrome web driver
driver = webdriver.Chrome()

# Open the first URL in the first tab
driver.get(url1)

# Open a new tab and switch to it
driver.execute_script("window.open('', '_blank');")
driver.switch_to.window(driver.window_handles[1])

# Open the second URL in the second tab
driver.get(url2)

attempt one:

ActionChains(driver).key_down(Keys.CONTROL).send_keys('t').key_up(Keys.CONTROL).perform()
ActionChains(driver).send_keys(Keys.ENTER)

attempt two:

driver.find_element(By.TAG_NAME,'body').send_keys(Keys.CONTROL + Keys.TAB)

attempt three:

action_chains = ActionChains(driver)
action_chains.key_down(Keys.CONTROL).send_keys('1').key_up(Keys.CONTROL).perform()

Read more here: Source link