selenium remotewebdriver with python - performance logging?

2024/9/20 0:04:20

I'm trying to get back some performance log info from a remote webdriver instance. I'm using the Python Selenium bindings.

From what I can see, this is information I should be able to get back. Think it may only be available with ChromeDriver. I'm currently using FireFox but can easily switch over if it gets the info I want.

However, I'm new to Python (but learning!) and documentation around the capabilities dictionaries (when used for performance logging) for Python seems to be a bit limited (or my google-fu is weak this morning).

I've found the following:

DesiredCapabilities caps = DesiredCapabilities.chrome();
LoggingPreferences logPrefs = new LoggingPreferences();
logPrefs.enable("performance", Level.INFO);
caps.setCapability(CapabilityType.LOGGING_PREFS, logPrefs);
driver = new RemoteWebDriver("http://localhost:9515", caps);

Which looks like it should do what I need. But it's Java. I'm not quite sure how I'd go about converting this to Python. Assuming it's possible.

Any ideas?

Answer

In case anyone is wondering, this seems to do the trick for me:

(Assuming you're using selenium remote)

url = 'http://remote instance IP:PORT/wd/hub'
descaps = {'browserName': 'chrome', 'loggingPrefs': {'performance': 'INFO'}}driver = webdriver.Remote(command_executor=url, desired_capabilities=descaps)driver.command_executor._commands.update({'getAvailableLogTypes': ('GET', '/session/sessionId/log/types'), {'getLog': ('POST', '/session/$sessionId/log')})getlog = driver.execute('getLog', {'type': 'performance'})['value']

(Of the two added commands 'getAvailableLogTypes' and 'getLog' - you only see the former in the above code snippet. The latter simply returns a list of the available log types on your remote session.)

Now all I need to do is interpret it ....

https://en.xdnf.cn/q/72542.html

Related Q&A

Python - replace unicode emojis with ASCII characters

I have an issue with one of my current weekend projects. I am writing a Python script that fetches some data from different sources and then spits everything out to an esc-pos printer. As you might ima…

How do I get my python object back from a QVariant in PyQt4?

I am creating a subclass of QAbstractItemModel to be displayed in an QTreeView.My index() and parent() function creates the QModelIndex using the QAbstractItemModel inherited function createIndex and p…

Django serializers vs rest_framework serializers

What is the difference between Django serializers vs rest_framework serializers? I making a webapp, where I want the API to be part of the primary app created by the project. Not creating a separate A…

Pandas replace non-zero values

I know I can replace all nan values with df.fillna(0) and replace a single value with df.replace(-,1), but how can I replace all non-zero values with a single value?

Pandas percentage change using group by

Suppose I have the following DataFrame: df = pd.DataFrame({city: [a, a, a, b, b, c, d, d, d], year: [2013, 2014, 2016, 2015, 2016, 2013, 2016, 2017, 2018],value: [10, 12, 16, 20, 21, 11, 15, 13, 16]})A…

Django cannot find my static files

I am relatively new to web dev. and I am trying to build my first web application. I have my static folder in project_root/static but for some reason, I keep getting 404s when I run the server:Not Foun…

How can I find intersection of two large file efficiently using python?

I have two large files. Their contents looks like this:134430513125296589151963957125296589The file contains an unsorted list of ids. Some ids may appear more than one time in a single file. Now I want…

Failed to load the native TensorFlow runtime - TensorFlow 2.1

I have a desktop computer and a notebook, when I tried to install tensorflow on a notebook just by using pip install tensorflow it worked ok, then I tried the same on my desktop computer and when I tri…

(Python) Issues with directories that have special characters

OS: Windows server 03 Python ver: 2.7For the code below, its runs fine when I substitute "[email protected]" with "fuchida". If I use the email format for directory name I get the f…

LibCST: Converting arbitrary nodes to code

Is it possible to dump an arbitrary LibCST node into Python code? My use case is that I want to extract the code for functions that match a specific naming scheme. I can extract the FunctionDef nodes …