Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open console in firefox python selenium?

Im trying to open firefox console through Selenium with Python. How can I open firefox console with python selenium? Is it possible to send keys to the driver or something like that?

like image 458
patricmj Avatar asked Nov 05 '15 14:11

patricmj


2 Answers

I know this is relatively old but I ran into this issue recently. I got firefox to automatically open devtools by passing in a browser process argument "-devtools".

Selenium: 3.14 geckodriver: 0.21.0 firefox: 61.0.1

  from __future__ import print_function

  from datetime import datetime
  import logging
  import os

  from selenium import webdriver
  from selenium.webdriver.firefox.options import Options as FirefoxOptions

  def before_scenario(context, scenario):
    logging.info("RUNNING: " + scenario.name)
    print("Browser Test starting.\n")

    options = FirefoxOptions()
    options.log.level = "trace"
    options.add_argument("-devtools")

    if 'headless' in os.environ and os.environ['headless'] == '1':
         options.headless = True

    context.driver = webdriver.Firefox(firefox_options=options)


    context.driver.maximize_window()
like image 162
darkknight51 Avatar answered Sep 29 '22 11:09

darkknight51


Try to simulate the same procedure as a "regular" firefox window using the send_keys function:

from selenium.webdriver.common.keys import Keys
driver.find_element_by_tag_name('body').send_keys(Keys.CONTROL + Keys.SHIFT + 'k')
like image 37
Javitronxo Avatar answered Sep 29 '22 10:09

Javitronxo