Search code examples
pythonhelium

Python using helium open new tab in a browser


Hello im trying to open new tab in browser using helium. I have tried this with no success:

start_chrome('www.google.com')

press(CONTROL + 'T')

I cant really find anything helpful on https://selenium-python-helium.readthedocs.io/en/latest/api.html?highlight=


Solution

  • Caveat - haven't tested this, but do expect it to work.

    tl;dr - Helium isn't actively maintained. Pls consider this going forward.

    There's a single project owner who refuses to look at any new issues unless paid consulting fees or if you submit a PR and fix issues yourself. Not well documented either. Also is hardcoded to support Selenium v3.141 with no plans to support 4.x in the future. Such a pity - really a great concept, albeit with some problems

    As for the Key functionality, the package's __init__.py does a direct import from webdriver code to expose keys within its own library. Internally, I see that its doing a send_keys() call to the active_element.

    enter image description here

    As per the documentation, what you're trying to do is supposed to work: https://selenium-python-helium.readthedocs.io/en/latest/api.html?highlight=Key#helium.press

    To press multiple keys at the same time, concatenate them with +. For example, to press Control + a, call:

    press(CONTROL + 'a')
    

    You may have better luck doing this: https://www.tutorialspoint.com/what-to-press-ctrl-plusc-on-a-page-in-selenium-with-python

    from selenium.webdriver import ActionChains
    from selenium.webdriver.common.keys import Keys
    
    # action chain object creation
    a = ActionChains(driver)
    # perform the ctrl+T pressing action
    a.key_down(Keys.CONTROL).send_keys('T').key_up(Keys.CONTROL).perfo
    rm()
    

    Helium does support making native calls against the driver - you just need to "get" it, then you can do the ActionChains call:

    driver = helium.get_driver()
    

    See here: https://selenium-python-helium.readthedocs.io/en/latest/api.html?highlight=get#helium.get_driver