Skip to content

Commit 01c1768

Browse files
committed
[py] Update Python documentation (modernization)
1 parent ad79e29 commit 01c1768

File tree

5 files changed

+67
-51
lines changed

5 files changed

+67
-51
lines changed

py/docs/README.rst

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ How to build docs
1212

1313
One can build the Python documentation without doing a full bazel build. The
1414
following instructions will build the setup a virtual environment and installs tox,
15-
clones the selenium repo and then runs ``tox -c py/tox.ini`` building the Python documentation.
15+
clones the selenium repo and then runs ``tox -c py/tox.ini -e docs``, building the
16+
Python documentation.
1617

1718
.. code-block:: console
1819
@@ -28,8 +29,10 @@ clones the selenium repo and then runs ``tox -c py/tox.ini`` building the Python
2829
This works in a similar manner as the larger selenium bazel build, but does just the Python
2930
documentation portion.
3031

32+
3133
What is happening under the covers of tox, sphinx
3234
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
35+
3336
tox is essentially a build tool for Python. Here it sets up its own virtual env and installs
3437
the documentation packages (sphinx and jinja2) as well as the required selenium python
3538
dependencies. Then tox runs the ``sphinx-autogen`` command to generate autodoc stub pages.
@@ -42,18 +45,20 @@ available and currently the documentation is fairly small and not complex. So so
4245
understanding of reStructuredText and the Sphinx tool chain should be sufficient to contribute
4346
and develop the Python docs.
4447

45-
To clean up the build / tox cache
46-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
47-
Although there is a Sphinx Makefile option to clean up using the tox environment above, one can
48-
manually clean the build by deleting the build directory on the root (``selenium/build`` using the
49-
default directory on git clone). Note that both Sphinx and tox cache parts of their build and
50-
recognize changes to speed up their respective builds. To start fresh, delete the aformentioned
51-
directory to clean the Sphinx cache and delete the ``selenium/py/.tox`` directory to clean the
52-
tox environment.
48+
49+
To clean up the build assets and tox cache
50+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
51+
52+
Although there is a Sphinx Makefile option, to clean up using the tox environment above, one can
53+
manually clean the build assets by deleting the ``build`` directory on the root (``selenium/build``
54+
using the default directory on git clone). Note that tox caches parts of the build and recognizes
55+
changes to speed up the build. To start fresh, delete the aformentioned directory to clean the
56+
Sphinx build assets and delete the ``selenium/py/.tox`` directory to clean the tox environment.
5357

5458

5559
Known documentation issues
5660
==========================
61+
5762
The API Reference primarily builds from the source code. But currently the initial template stating
5863
which modules to document is hard coded within ``py/docs/source/api.rst``. So if modules are added or
5964
removed, then the generated docs will be inaccurate. It would be preferred that the API docs generate
@@ -63,11 +68,13 @@ soley from the code if possible. This is being tracked in
6368
We are working through the Sphinx build warnings and errors, trying to clean up both the syntax and
6469
the build.
6570

71+
6672
Contributing to Python docs
6773
===========================
74+
6875
First it is recommended that you read the main `CONTRIBUTING.md <https://github.com/SeleniumHQ/selenium/blob/trunk/CONTRIBUTING.md>`_.
6976

70-
Some steps for contibuting to the Python documentation ..
77+
Some steps for contibuting to the Python documentation ...
7178

7279
- Check out changes locally using instructions above.
7380
- Try to resolve any warnings/errors.

py/docs/requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
Jinja2==3.1.6
22
Sphinx==8.2.3
3+
sphinx-material==0.0.36

py/docs/selenium_logo_small.png

647 Bytes
Loading

py/docs/source/conf.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949

5050
# General information about the project.
5151
project = 'Selenium'
52-
copyright = '2009-2024 Software Freedom Conservancy'
52+
copyright = '2009-2025 Software Freedom Conservancy'
5353

5454
# The version info for the project you're documenting, acts as replacement for
5555
# |version| and |release|, also used in various other places throughout the
@@ -97,9 +97,8 @@
9797

9898
# -- Options for HTML output ---------------------------------------------------
9999

100-
# The theme to use for HTML and HTML Help pages. See the documentation for
101-
# a list of builtin themes.
102-
html_theme = 'default'
100+
# The theme to use for HTML and HTML Help pages
101+
html_theme = 'sphinx_material'
103102

104103
# Theme options are theme-specific and customize the look and feel of a theme
105104
# further. For a list of options available for each theme, see the
@@ -118,7 +117,7 @@
118117

119118
# The name of an image file (relative to this directory) to place at the top
120119
# of the sidebar.
121-
#html_logo = None
120+
html_logo = '../selenium_logo_small.png'
122121

123122
# The name of an image file (within the static path) to use as favicon of the
124123
# docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
@@ -146,13 +145,13 @@
146145
#html_additional_pages = {}
147146

148147
# If false, no module index is generated.
149-
#html_domain_indices = True
148+
html_domain_indices = True
150149

151150
# If false, no index is generated.
152-
#html_use_index = True
151+
html_use_index = True
153152

154153
# If true, the index is split into individual pages for each letter.
155-
#html_split_index = False
154+
html_split_index = True
156155

157156
# If true, links to the reST sources are added to the pages.
158157
html_show_sourcelink = True

py/docs/source/index.rst

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ The `selenium` package is used to automate web browser interaction from Python.
1414
+-----------------+--------------------------------------------------------------------------------------+
1515
| **GitHub**: | https://github.com/SeleniumHQ/Selenium |
1616
+-----------------+--------------------------------------------------------------------------------------+
17-
| **PyPI**: | https://pypi.org/project/selenium/ |
17+
| **PyPI**: | https://pypi.org/project/selenium |
18+
+-----------------+--------------------------------------------------------------------------------------+
19+
| **API Docs**: | https://selenium.dev/selenium/docs/api/py/api.html |
1820
+-----------------+--------------------------------------------------------------------------------------+
1921
| **IRC/Slack**: | `Selenium chat room <https://www.selenium.dev/support/#ChatRoom>`_ |
2022
+-----------------+--------------------------------------------------------------------------------------+
@@ -33,21 +35,22 @@ If you have `pip <https://pip.pypa.io/>`_ on your system, you can simply install
3335

3436
pip install -U selenium
3537

36-
Alternately, you can download the source distribution from `PyPI <https://pypi.org/project/selenium/#files>`, unarchive it, and run::
37-
38-
python -m pip install .
39-
40-
Note: You may want to consider using `virtualenv <http://www.virtualenv.org/>`_ to create isolated Python environments.
38+
You may want to consider using a `virtual environment <https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments>`_
39+
to create isolated Python environments.
4140

4241
Drivers
4342
=======
4443

45-
Selenium requires a driver to interface with the chosen browser. Firefox,
46-
for example, requires `geckodriver <https://github.com/mozilla/geckodriver/releases>`_, which needs to be installed before the below examples can be run. Make sure it's in your `PATH`, e. g., place it in `/usr/bin` or `/usr/local/bin`.
44+
Selenium requires a driver to interface with the chosen browser (chromedriver, edgedriver, geckodriver, etc).
4745

48-
Failure to observe this step will give you an error `selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.`
46+
In older versions of Selenium, it was necessary to install and manage these drivers yourself. You had to make sure the driver
47+
executable was available on your system `PATH`, or specified explicitly in code. Modern versions of Selenium handle browser and
48+
driver installation for you with `Selenium Manager <https://www.selenium.dev/documentation/selenium_manager>`_. You generally
49+
don't have to worry about driver installation or configuration now that it's done for you when you instantiate a WebDriver.
50+
Selenium Manager works with most supported platforms and browsers. If it doesn't meet your needs, you can still install and
51+
specify browsers abnd drivers yourself.
4952

50-
Other supported browsers will have their own drivers available. Links to some of the more popular browser drivers follow.
53+
Links to some of the more popular browser drivers:
5154

5255
+--------------+-----------------------------------------------------------------------+
5356
| **Chrome**: | https://chromedriver.chromium.org/downloads |
@@ -62,59 +65,65 @@ Other supported browsers will have their own drivers available. Links to some of
6265
Example 0:
6366
==========
6467

65-
* open a new Firefox browser
66-
* load the page at the given URL
68+
* launch a new Chrome browser
69+
* load a web page
70+
* close the browser
6771

6872
.. code-block:: python
6973
7074
from selenium import webdriver
7175
72-
browser = webdriver.Firefox()
73-
browser.get('http://selenium.dev/')
76+
77+
driver = webdriver.Chrome()
78+
driver.get('https://selenium.dev/')
79+
driver.quit()
7480
7581
Example 1:
7682
==========
7783

78-
* open a new Firefox browser
79-
* load the Yahoo homepage
80-
* search for "seleniumhq"
84+
* launch a new Chrome browser
85+
* load the Selenium documentation page
86+
* find the "Webdriver" link
87+
* click the "WebDriver" link
8188
* close the browser
8289

8390
.. code-block:: python
8491
8592
from selenium import webdriver
8693
from selenium.webdriver.common.by import By
87-
from selenium.webdriver.common.keys import Keys
8894
89-
browser = webdriver.Firefox()
9095
91-
browser.get('http://www.yahoo.com')
92-
assert 'Yahoo' in browser.title
96+
driver = webdriver.Chrome()
97+
98+
driver.get('https://selenium.dev/documentation')
99+
assert 'Selenium' in driver.title
93100
94-
elem = browser.find_element(By.NAME, 'p') # Find the search box
95-
elem.send_keys('seleniumhq' + Keys.RETURN)
101+
elem = driver.find_element(By.ID, 'm-documentationwebdriver')
102+
elem.click()
103+
assert 'WebDriver' in driver.title
96104
97-
browser.quit()
105+
driver.quit()
98106
99107
Example 2:
100108
==========
101109

102-
Selenium WebDriver is often used as a basis for testing web applications. Here is a simple example using Python's standard `unittest <http://docs.python.org/3/library/unittest.html>`_ library:
110+
Selenium WebDriver is often used as a basis for testing web applications. Here is a simple example using Python's standard `unittest <http://docs.python.org/3/library/unittest.html>`_ library:
103111

104112
.. code-block:: python
105113
106114
import unittest
107115
from selenium import webdriver
108116
117+
109118
class GoogleTestCase(unittest.TestCase):
110119
111120
def setUp(self):
112-
self.browser = webdriver.Firefox()
113-
self.addCleanup(self.browser.quit)
121+
self.driver = webdriver.Firefox()
122+
self.addCleanup(self.driver.quit)
114123
115124
def test_page_title(self):
116-
self.browser.get('http://www.google.com')
117-
self.assertIn('Google', self.browser.title)
125+
self.driver.get('https://www.google.com')
126+
self.assertIn('Google', self.driver.title)
118127
119128
if __name__ == '__main__':
120129
unittest.main(verbosity=2)
@@ -143,9 +152,9 @@ Contributing
143152

144153
- Create a branch for your work
145154
- Ensure `tox` is installed (using a `virtualenv` is recommended)
146-
- `python3.8 -m venv .venv && . .venv/bin/activate && pip install tox`
155+
- Run: `python -m venv venv && venv/bin/activate && pip install tox`
147156
- After making changes, before committing execute `tox -e linting`
148-
- If tox exits `0`, commit and push otherwise fix the newly introduced breakages.
157+
- If tox exits `0`, commit and push. Otherwise fix the newly introduced styke violations.
149158
- `flake8` requires manual fixes
150-
- `black` will often rewrite the breakages automatically, however the files are unstaged and should staged again.
151-
- `isort` will often rewrite the breakages automatically, however the files are unstaged and should staged again.
159+
- `black` will rewrite the violations automatically, however the files are unstaged and should staged again.
160+
- `isort` will rewrite the viiolations automatically, however the files are unstaged and should staged again.

0 commit comments

Comments
 (0)