3

What I've tried:

driver.execute_script("console.log('help me to see console print')")

But No any result.

2 Answers 2

4

You have got it!

driver.get("https://www.google.com")
driver.execute_script(f"console.log('{driver.current_url}');")

enter image description here

Sign up to request clarification or add additional context in comments.

3 Comments

@toptalent I just added the get for the example. if you need to access the log from the browser to your code that's a different question...
@MosheSlavin semi colon is not mandatory in javascript
@PDHide correct! it's just a convention thanks for pointing that out.
0

After execution javascript, need sometime to load it into browser dom.
So I added some time sleep under that code line.

driver.execute_script("console.log('help me to see console print')")
time.sleep(10)

Now it was printed:

help me to see console print

Comments

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.