Reputation: 405
I am trying to get logs from Chrome's console using Selenium with Python and a little bit lost because it is my first experience with it.
In general, the code works and prints logs, but I need to see some specific events, that I normally see by typing a command _newsb.getEv.getBuffer()
(it is an imaginary command, I am using something similar). With Selenium, I am trying to input it like this driver.execute_script("_newsb.getEv.getBuffer()")
, but I don't see events.
Here is the code:
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
dc = DesiredCapabilities.CHROME
dc['goog:loggingPrefs'] = { 'browser':'ALL' }
driver = webdriver.Chrome(desired_capabilities=dc, service_args=["--verbose", "--log-path=D:\\qc1.log"])
driver.implicitly_wait(30)
driver.get('https://www.somewebsite.com/')
page = driver.find_element_by_tag_name("html")
driver.execute_script("window.scrollTo(0, 400)")
time.sleep(3)
driver.execute_script("_newsb.getEv.getBuffer()")
time.sleep(3)
driver.execute_script("window.scrollTo(0, window.scrollY + 400)")
time.sleep(3)
driver.execute_script("window.scrollTo(0, window.scrollY + 400)")
time.sleep(1)
for entry in driver.get_log('browser'):
print(entry)
driver.quit()
Could someone please point out what I am doing wrong and how do you input in console with Selenium and Python? Any advice is appreciated.
Also, how to see all logs, including info and Verbose, not just errors?
Upvotes: 1
Views: 1769
Reputation: 19939
options.set_capability("goog:loggingPrefs", { # old: loggingPrefs
"browser": "ALL"})
driver = webdriver.Chrome(
options=options
)
# returns a list of all events
driver.execute_script("window.open('');")
driver.switch_to.window(driver.window_handles[1])
driver.get('http://www.google.com')
driver.execute_script("console.error('This is error')")
driver.execute_script("console.info('This is info')")
driver.execute_script("console.log('This is log')")
logs = driver.get_log("browser")
print(logs)
sleep(100000)
This prints all the 3 types of logs i am not sure if you are looking for this
Upvotes: 5