Selenium on Mac 使用 Python,如何发出键盘命令

Selenium on Mac Using Python, how to issue keyboard commands

我一直在尝试在 brave 浏览器中使用 python 中的 selenium 发出键盘命令。 我试过这样的事情: body = browser.find_element_by_tag_name("body")

body.send_keys(Keys.COMMAND,"t") 这似乎 运行 很好,但没有效果。我究竟做错了什么?好像我执行命令到错误的地方,但如果是这样,我应该把它发送到哪里呢?

我基本上是这样做的:

        from selenium.webdriver.chrome.options import Options 
        import time 
        from selenium.webdriver.common.by import By
        from selenium.webdriver.common.keys import Keys 
  
options = Options()
options.binary_location = '/Applications/Brave Browser.app/Contents/MacOS/Brave Browser'
driver_path = '/Users/[myusername]/Desktop/seleni/chromedriver'

browser = webdriver.Chrome(options = options, executable_path = driver_path)
browser.get('chrome://newtab') #or whatever page you want

#Here's the important part vvv
browser.execute_script("window.open('https://duckduckgo.com/?q=%27&t=brave&ia=answer')")````

Hopefully this helps in some way. Sorry if I'm a bit of a newbie at this kind of stuff.