0

How to send CTRL + Shift + I in selenium using ActionChains. I followed many examples such as:

Web Driver API | 7.2. Action Chains

For Selenium with Python, how can i get it to press CTRL, SHIFT, i?

But, those don't work for me. I don't know, what I missed. Maybe because I using a different script. Please help me to send CTRL + Shift + I.

I re-use existing Selenium browser. I was trying to use Action Chains and select an element. But, both are not working without any error logs.

def secondProccess(executor_url, session_id, data):
    options = Options()
    options.page_load_strategy = 'normal'
    options.add_argument("--disable-infobars")
    options.add_argument("--enable-file-cookies")
    capabilities = options.to_capabilities()
    driver = webdriver.Remote(command_executor=executor_url, desired_capabilities=capabilities)
    driver.close()
    driver.session_id = session_id
    link="https://google.com"
    
    driver.execute_script("window.open('{}');".format(link))
    action = webdriver.ActionChains(driver)

    ## Trying to use ActionChains
    action.send_keys(Keys.CONTROL, Keys.SHIFT, 'i').perform()

    ## Trying to use ActionChain key down
    action.key_down(Keys.CONTROL).key_down(Keys.SHIFT).send_keys("i").perform()

    ## Trying to use element
    driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL, Keys.SHIFT, 'i')

    sys.exit()
xdnroot
  • 155
  • 1
  • 1
  • 12

1 Answers1

0

Add this argument to the webdriver options.

options.add_argument('--auto-open-devtools-for-tabs');

However, please note that the --auto-open-devtools-for-tabs option does not apply to remote webdriver. So we have to add it on the non-remote driver. In my case, I applied it to the createFirstDriver() function because this function that I use to create a driver which then I remote in secondProccess ().

If you are confused, what I mean, I use the script from here, please check the complete script there or here:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from multiprocessing import Process
import time

# The main process calls this function to create the driver instance.
def createFirstDriver():
    options = Options()
    options.add_argument('--disable-infobars')
    options.add_argument('--auto-open-devtools-for-tabs');
    driver = webdriver.Chrome(chrome_options=options, port=9515)
    return driver

# Called by the second process only.
def secondProcess(executor_url, session_id):
    options = Options()
    options.add_argument("--disable-infobars")
    options.add_argument("--enable-file-cookies")
    capabilities = options.to_capabilities()
    same_driver = webdriver.Remote(command_executor=executor_url, desired_capabilities=capabilities)
    same_driver.close()
    same_driver.session_id = session_id
    same_driver.get("https://www.wikipedia.org")
    time.sleep(4)
    same_driver.quit()

if __name__ == '__main__':
    driver = createDriverInstance()
    driver.get("https://sntch.com")
    time.sleep(2)

    # Pass the driver session and command_executor to the second process.
    p = Process(target=secondProcess, args=(driver.command_executor._url,driver.session_id))
    p.start()

The script above will open chrome developer tools (ctrl + shift + i) automatically, including when we access it using the remote driver in the secondProccess() function.

Good luck.

xdnroot
  • 155
  • 1
  • 1
  • 12