Skip to content

Commit

Permalink
Fix broken links
Browse files Browse the repository at this point in the history
Line width 79 chars
  • Loading branch information
baijum committed Oct 18, 2020
1 parent 3b22bce commit fd73729
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 62 deletions.
1 change: 1 addition & 0 deletions source/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ Other supported browsers will have their own drivers available. Links to some of
| **Safari**: | https://webkit.org/blog/6900/webdriver-support-in-safari-10/ |
+--------------+-----------------------------------------------------------------------+

For more information about driver installation, please refer the `official documentation <https://www.selenium.dev/documentation/en/webdriver/driver_requirements/>`_.

Detailed instructions for Windows users
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
120 changes: 58 additions & 62 deletions source/locating-elements.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Locating Elements
-----------------

There are various strategies to locate elements in a page. You can use
the most appropriate one for your case. Selenium provides the following
methods to locate elements in a page:
There are various strategies to locate elements in a page. You can use the most
appropriate one for your case. Selenium provides the following methods to
locate elements in a page:

- `find_element_by_id`
- `find_element_by_name`
Expand All @@ -28,8 +28,8 @@ methods to locate elements in a page:
- `find_elements_by_css_selector`


Apart from the public methods given above, there are two private
methods which might be useful for locating page elements:
Apart from the public methods given above, there are two private methods which
might be useful for locating page elements:

- `find_element`
- `find_elements`
Expand Down Expand Up @@ -58,10 +58,10 @@ These are the attributes available for `By` class::
Locating by Id
~~~~~~~~~~~~~~

Use this when you know the `id` attribute of an element. With this
strategy, the first element with a matching `id` attribute will
be returned. If no element has a matching `id` attribute,
a ``NoSuchElementException`` will be raised.
Use this when you know the `id` attribute of an element. With this strategy,
the first element with a matching `id` attribute will be returned. If no
element has a matching `id` attribute, a ``NoSuchElementException`` will be
raised.

For instance, consider this page source::

Expand All @@ -83,10 +83,10 @@ The form element can be located like this::
Locating by Name
~~~~~~~~~~~~~~~~

Use this when you know the `name` attribute of an element. With this
strategy, the first element with a matching `name` attribute will
be returned. If no element has a matching `name` attribute,
a ``NoSuchElementException`` will be raised.
Use this when you know the `name` attribute of an element. With this strategy,
the first element with a matching `name` attribute will be returned. If no
element has a matching `name` attribute, a ``NoSuchElementException`` will be
raised.

For instance, consider this page source::

Expand Down Expand Up @@ -115,26 +115,24 @@ button::
Locating by XPath
~~~~~~~~~~~~~~~~~

XPath is the language used for locating nodes in an XML document. As
HTML can be an implementation of XML (XHTML), Selenium users can
leverage this powerful language to target elements in their web
applications. XPath supports the simple methods of locating by
id or name attributes and extends them by opening up all sorts
of new possibilities such as locating the third checkbox on the page.

One of the main reasons for using XPath is when you don't have a
suitable id or name attribute for the element you wish to locate. You
can use XPath to either locate the element in absolute terms (not
advised), or relative to an element that does have an id or name
attribute. XPath locators can also be used to specify elements via
attributes other than id and name.

Absolute XPaths contain the location of all elements from the root
(html) and as a result are likely to fail with only the slightest
adjustment to the application. By finding a nearby element with an id
or name attribute (ideally a parent element) you can locate your
target element based on the relationship. This is much less likely to
change and can make your tests more robust.
XPath is the language used for locating nodes in an XML document. As HTML can
be an implementation of XML (XHTML), Selenium users can leverage this powerful
language to target elements in their web applications. XPath supports the
simple methods of locating by id or name attributes and extends them by opening
up all sorts of new possibilities such as locating the third checkbox on the
page.

One of the main reasons for using XPath is when you don't have a suitable id or
name attribute for the element you wish to locate. You can use XPath to either
locate the element in absolute terms (not advised), or relative to an element
that does have an id or name attribute. XPath locators can also be used to
specify elements via attributes other than id and name.

Absolute XPaths contain the location of all elements from the root (html) and as
a result are likely to fail with only the slightest adjustment to the
application. By finding a nearby element with an id or name attribute (ideally
a parent element) you can locate your target element based on the relationship.
This is much less likely to change and can make your tests more robust.

For instance, consider this page source::

Expand Down Expand Up @@ -170,7 +168,8 @@ The username element can be located like this::

1. First form element with an input child element with `name` set to `username`

2. First input child element of the form element with attribute `id` set to `loginForm`
2. First input child element of the form element with attribute `id` set to
`loginForm`

3. First input element with attribute `name` set to `username`

Expand All @@ -180,29 +179,27 @@ The "Clear" button element can be located like this::
clear_button = driver.find_element_by_xpath("//form[@id='loginForm']/input[4]")


1. Input with attribute `name` set to `continue` and
attribute `type` set to `button`
1. Input with attribute `name` set to `continue` and attribute `type` set to
`button`

2. Fourth input child element of the form element with attribute `id` set to `loginForm`
2. Fourth input child element of the form element with attribute `id` set to
`loginForm`

These examples cover some basics, but in order to learn more, the
following references are recommended:
These examples cover some basics, but in order to learn more, the following
references are recommended:

* `W3Schools XPath Tutorial <https://www.w3schools.com/xml/xpath_intro.asp>`_
* `W3C XPath Recommendation <http://www.w3.org/TR/xpath>`_
* `XPath Tutorial
<http://www.zvon.org/comp/r/tut-XPath_1.html>`_
- with interactive examples.

There are also a couple of very useful Add-ons that can assist in
discovering the XPath of an element:
Here is a couple of very useful Add-ons that can assist in discovering the XPath
of an element:

* `XPath Checker
<https://addons.mozilla.org/en-US/firefox/addon/xpath-checker/>`_ -
suggests XPath and can be used to test XPath results.
* `Firebug <https://addons.mozilla.org/en-US/firefox/addon/firebug/>`_ -
XPath suggestions are just one of the many powerful features of this
very useful add-on.
* `xPath Finder
<https://addons.mozilla.org/en-US/firefox/addon/xpath_finder>`_ -
Plugin to get the elements xPath.
* `XPath Helper
<https://chrome.google.com/webstore/detail/hgimnogjllphhhkhlmebbmlgjoejdpjl>`_ -
for Google Chrome
Expand All @@ -212,9 +209,9 @@ Locating Hyperlinks by Link Text
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Use this when you know the link text used within an anchor tag. With this
strategy, the first element with the link text matching the provided value
will be returned. If no element has a matching link text
attribute, a ``NoSuchElementException`` will be raised.
strategy, the first element with the link text matching the provided value will
be returned. If no element has a matching link text attribute, a
``NoSuchElementException`` will be raised.

For instance, consider this page source::

Expand All @@ -235,10 +232,9 @@ The continue.html link can be located like this::
Locating Elements by Tag Name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Use this when you want to locate an element by tag name. With this
strategy, the first element with the given tag name will be returned.
If no element has a matching tag name, a ``NoSuchElementException``
will be raised.
Use this when you want to locate an element by tag name. With this strategy, the
first element with the given tag name will be returned. If no element has a
matching tag name, a ``NoSuchElementException`` will be raised.

For instance, consider this page source::

Expand All @@ -257,10 +253,10 @@ The heading (h1) element can be located like this::
Locating Elements by Class Name
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Use this when you want to locate an element by class name.
With this strategy, the first element with the matching class name
attribute will be returned. If no element has a matching class name attribute,
a ``NoSuchElementException`` will be raised.
Use this when you want to locate an element by class name. With this strategy,
the first element with the matching class name attribute will be returned. If
no element has a matching class name attribute, a ``NoSuchElementException``
will be raised.

For instance, consider this page source::

Expand All @@ -277,10 +273,10 @@ The "p" element can be located like this::
Locating Elements by CSS Selectors
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Use this when you want to locate an element using CSS selector syntax.
With this strategy, the first element matching the given CSS selector
will be returned. If no element matches the provided CSS selector,
a ``NoSuchElementException`` will be raised.
Use this when you want to locate an element using CSS selector syntax. With
this strategy, the first element matching the given CSS selector will be
returned. If no element matches the provided CSS selector, a
``NoSuchElementException`` will be raised.

For instance, consider this page source::

Expand Down

0 comments on commit fd73729

Please sign in to comment.