2

I want to make a fetch call fetch("https://www.test.com") in chrome dev tools console.

--auto-open-devtools-for-tabs opens the dev tools. However, I'm not sure if it is possible to navigate to console and type fetch("https://www.test.com")

            chrome_options = Options()
            chrome_options.add_argument('--headless')
            chrome_options.add_argument('--no-sandbox')
            chrome_options.add_argument('--disable-dev-shm-usage')
            chrome_options.add_argument('--auto-open-devtools-for-tabs')

            driver = webdriver.Chrome(seleniumwire_options={'verify_ssl': False},
                                      executable_path=ChromeDriverManager(chrome_type='google-chrome').install(),
                                      chrome_options=chrome_options
                                      )

1 Answer 1

2

Executing commands in the Chrome console for the most part is simply executing JavaScript code. then you could just execute like follows in Selenium:

driver.execute_script("fetch('https://www.test.com'")

if you needed to see the returned value of a command since you are using headless mode then it could be something like:

print(self.driver.execute_script("fetch('https://www.test.com')"))
Sign up to request clarification or add additional context in comments.

3 Comments

I believe the closing bracket is missing. And Print returns None print(self.driver.execute_script("fetch('https://www.test.com')"))
@user3587025, check if it works without headless mode please
I tried in headless mode chrome_options.add_argument('--headless') Returns None

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.