I am using python + selenium for web browser automation and getting this error.
DevTools listening on ws://127.0.0.1:57671/devtools/browser/8a586f7c-5f2c-4d10-8174-7a7bf50e49b5
[5096:1196:0909/183254.362:ERROR:mf_helpers.cc(14)] Error in dxva_video_decode_accelerator_win.cc on line 517
The problem arises when the program reaches this part of code:-
def send_comments(driver):
add_comments = driver.find_elements_by_class_name('add')
comments = driver.find_elements_by_xpath("//form[@class='addCommentexpand']//textarea[contains(@placeholder,'Add a comment')]")
submit_comments = driver.find_elements_by_xpath("//button[text()='Comment']")
i = 0
for add, comment, submit in zip(add_comments, comments, submit_comments):
print("comment begins")
add.click()
print("+add comment clicked")
comment.click()
print("comment textbox clicked")
comment.send_comments("Amazing Art")
print("text typed")
submit.click()
print("comment submited")
i += 1
if i > 5:
driver.close()
send_comments(driver)
Its also not logging in console. Can anyone tell whats the problem?
Based on Chanticleer in hide chromeDriver console in python
In your Python folder, find and edit this file:
Lib\site-packages\selenium\webdriver\common\services.py
Edit the Start() function by adding the creation flags this way: creationflags=CREATE_NO_WINDOW
from win32process import CREATE_NO_WINDOW
def start(self):
"""
Starts the Service.
:Exceptions:
- WebDriverException : Raised either when it can't start the service
or when it can't connect to the service
"""
try:
cmd = [self.path]
cmd.extend(self.command_line_args())
self.process = subprocess.Popen(cmd, env=self.env,
close_fds=platform.system() != 'Windows',
stdout=self.log_file, stderr=self.log_file, creationflags=CREATE_NO_WINDOW)
except TypeError:
raise
It works perfectly for me using python3.7 and selenium 3.141.0
DevTools listening on ws://127.0.0.1:9222/devtools/browser/
@AndreaCardaci in the documentation Load a URL in a separate context mentions that when using Google Chrome in Headless Mode:
The usual example code is run in a new disposable tab in a separated context (think of it as incognito profiles) each time.
As inorder to fetch the browser version since Chrome 62 the browser target URL is generated at runtime and can be obtained via the /json/version
endpoint and fallback to /devtools/browser
if not present.
Here is the relevant code:
const CDP = require('chrome-remote-interface');
async function doInNewContext(action) {
// fetch the browser version (since Chrome 62 the browser target URL is
// generated at runtime and can be obtained via the '/json/version'
// endpoint, fallback to '/devtools/browser' if not present)
const {webSocketDebuggerUrl} = await CDP.Version();
// connect to the DevTools special target
const browser = await CDP({
target: webSocketDebuggerUrl || 'ws://localhost:9222/devtools/browser'
});
// create a new context
const {Target} = browser;
const {browserContextId} = await Target.createBrowserContext();
const {targetId} = await Target.createTarget({
url: 'about:blank',
browserContextId
});
// connct to the new context
const client = await CDP({target: targetId});
// perform user actions on it
try {
await action(client);
} finally {
// cleanup
await Target.closeTarget({targetId});
await browser.close();
}
}
// this basically is the usual example
async function example(client) {
// extract domains
const {Network, Page} = client;
// setup handlers
Network.requestWillBeSent((params) => {
console.log(params.request.url);
});
// enable events then start!
await Promise.all([Network.enable(), Page.enable()]);
await Page.navigate({url: 'https://github.com'});
await Page.loadEventFired();
}
doInNewContext(example);
Moreover as per Obtain the browser target URL (ws://localhost:9222/devtools/browser/...) programmatically the endpoint is available over http://127.0.0.1:9222/json/version
in a webSocketDebuggerUrl
field. So alternatively, if you are starting chrome with the option --remote-debugging-port=0
, both port and endpoint are written to the DevToolsAcivePort file in browser profile folder.
Conclusion
This error doesn't impact your @Test
and you can ignore the error for the time being.
来源:https://stackoverflow.com/questions/52245604/devtools-listening-on-ws-127-0-0-157671-devtools-browser-8a586f7c-5f2c-4d10-8