0

I am using chromedriver.exe for Chrome version 80, and chrome version 80.0.3987.149. My selenium is up to date. I'm trying to send shortcuts to the browser in python and nothing is working. I've tried ActionChains, and elem.send_keys(). No shortcuts I've used have worked and I can't figure this out.

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
import pyautogui


driver = webdriver.Chrome(executable_path=r'path/to/exe')
driver.get('https://www.google.com')
time.sleep(8)

elem = driver.find_element_by_xpath("//body")
elem.send_keys(Keys.CONTROL,'t') #Opens a new tab

This doesn't work! I've tried an ActionChain approach and that doesn't work either. Any help would be awesome.

  • 1
    post your code trials. (really not sure what you mean by "I'm trying to send shortcuts to the browser") – pcalkins Mar 24 '20 at 19:02
  • @pcalkins I have edited the post to reflect code trial. – Alexander Tingling Mar 25 '20 at 16:29
  • I'm assuming the browser does launch? If so, use execute_script to send "window.open('about:blank', '_blank');" – pcalkins Mar 25 '20 at 16:52
  • @pcalkins yeah the browser opens. The problem is, I don't actually need to open a new tab, It seems like any shortcuts in general don't work with selenium. I'm sorry for the confusion. I find it strange there is no way to send shortcuts to a chrome webdriver. – Alexander Tingling Mar 25 '20 at 17:26
  • I finally grokked what you are trying to say there. You mean keyboard shortcuts for browser commands. The scope is limited to the DOM more or less. There used to be some support for it (not necessarily by design), but I think all the webdrivers/browsers dropped it. – pcalkins Mar 25 '20 at 18:51
  • @pcalkins that's sad to hear, I'll keep looking around though! – Alexander Tingling Mar 26 '20 at 13:36

0 Answers0