xpathwebdriver


Namexpathwebdriver JSON
Version 2.0.6 PyPI version JSON
download
home_pagehttps://github.com/joaduo/xpathwebdriver
SummarySelenium/webdriver wrapper for XPath and CSS selection
upload_time2024-10-14 04:40:37
maintainerNone
docs_urlNone
authorJoaquin Duo
requires_pythonNone
licenseMIT
keywords testing automation web unittest webdriver selenium xpath css
VCS
bugtrack_url
requirements pyvirtualdisplay selenium ipython Pillow parsel
Travis-CI No Travis.
coveralls test coverage No coveralls.
            xpathwebdriver
==============

|.github/workflows/xpwd_ci.yml|

A python wrapper for interacting with Selenium through XPath and CSS
selectors. You can now use XPaths like ``//div/text()``:

.. code:: python

   from xpathwebdriver.browser import Browser

   browser = Browser()

   # xpath returns text
   for idx, t in enumerate(browser.select_xpath('//div/text()')):
       print(idx, t)

   # css selector returns elements
   for idx, elem in enumerate(browser.select_css('.result__title')):
       print(idx, elem.text)

Which will return you a string as expected. Something webdriver API
makes more complicated.

Means you can write all your tests based on XPath.

Also adds:

-  Interactive shell for testing XPath manually and easily against a
   live browser

   -  You can share the interactive shell with a script, to keep track
      of errors/debugging

-  Multiple browser management
-  Browser life management (whether to keep the browser open or kill it
   on exit)

   -  Management is done through python contexts (``with`` statement)

-  Useful settings for local and remote (headless) testing

   -  Also supports environment variables as settings
   -  Plus allowing custom settings that you can also push through
      environment variables

-  Screenshots comparison and diff management
-  Virtual display management (so you can run “headless” in a remote
   instance)

   -  you can use VNC to access the remote Browser

-  Adding ``xpath``, ``css``, ``selector`` methods to returned
   ``WebElement`` objects, to keep the Xpath functionality

Ubuntu quick installation
~~~~~~~~~~~~~~~~~~~~~~~~~

You can opt to use Chromium to simplify installation:

::

   sudo apt-get install -y python3-pip imagemagick findimagedupes tightvncserver xserver-xephyr xvfb unzip chromium-browser
   # chromium-chromedriver (from 22.04 and on you no longer need to install this package, seems it's obsolete and comes with chromium itself)
   sudo pip3 install xpathwebdriver Pillow ipython

You can quickly test it running:

::

   xpathshell

That will open an interactive shell with a browser object. Use TAB to
autocomplete available API. Use ``browser.driver`` to directly access
the webdriver object.

General installation
--------------------

::

   pip install xpathwebdriver

1. Install xpathwebdriver using pip.
2. Install google chrome.
3. Download chromedriver for your Chrome version and install it in your
   path. https://chromedriver.chromium.org/downloads
4. That generally should work on a modern Linux System (not tested but
   should also work on other oses). Try example in section below
5. For image comparison install ``pip install Pillow``,
   ``findimagedupes`` and ``imagemagick`` packages for your OS. (they
   are not automatically installed to keep basic requirements low) On
   ubuntu: ``sudo apt install imagemagick findimagedupes``
6. For interactive shell install ``pip install ipython``

Check “Installing Selenium” section for other browsers and details.

Example
-------

.. code:: python

   from xpathwebdriver.browser import Browser

   browser = Browser()
   browser.get_url('https://duckduckgo.com/')
   browser.fill(".//*[@id='search_form_input_homepage']", 'xpathwebdriver\n')
   # Using xpath that returns text
   for idx, t in enumerate(browser.select_xpath('//div/text()')):
       print(idx, t)
   # Using css selector which returns elements
   for idx, elem in enumerate(browser.select_css('.result__title')):
       print(idx, elem.text)

Documentation and tutorials
---------------------------

-  Check ``examples`` directory
-  The ``BrowserAPI.md`` file has a quick list of Browser’s API
-  Use ``xpathsell -e`` to print available environment variables for
   settings
-  Use ``xpathsell --settings-help`` to print settings detailed
   documentation

   -  or optionally check ``xpathwebdriver/default_settings.py``

IPython interactive shell
-------------------------

First install ipython ``pip install ipython`` (not installed to keep
basic requirements low) Run the ``xpathshell`` in your terminal, and you
should see something like:

::

   $ xpathshell
   Python 3.7.5rc1 (default, Oct  8 2019, 16:47:45)
   Type 'copyright', 'credits' or 'license' for more information
   IPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help.

   XpathBrowser in 'b' or 'browser' variables
    Current url: data:,
   In [1]: b.get('github.com/joaduo/xpathwebdriver/')
   INFO 05:53:35:  Current url: https://github.com/joaduo/xpathwebdriver/

For a faster development and debugging cycles you can run an interactive
shell which will let access the browser.

Or pass the url in the command arguments. Eg:
``xpathshell github.com/joaduo/xpathwebdriver/``

Inside IPython you can enter ``browser.select_xpath?`` to get
documentation and can access API docs.

More ``XpathBrowser`` details at:

-  https://github.com/joaduo/xpathwebdriver/blob/master/BrowserAPI.md
-  https://github.com/joaduo/xpathwebdriver/blob/master/xpathwebdriver/xpath_browser.py
-  https://github.com/joaduo/xpathwebdriver/blob/master/xpathwebdriver_tests/test_XpathBrowser.py

Using unittest library
~~~~~~~~~~~~~~~~~~~~~~

.. code:: python

   import unittest
   from xpathwebdriver.webdriver_manager import get_browser

   class SearchEnginesDemo(unittest.TestCase):
       def test_duckduckgo(self):
           with get_browser() as browser:
               browser.get_url('https://duckduckgo.com/')
               browser.fill('.//*[@id="search_form_input_homepage"]', 'xpathwebdriver\n')

Check a more options in the ``examples`` directory.

Installing Selenium
-------------------

Under Ubuntu you should easily install Selenium/Webdrivar with
``sudo apt install chromium-browser chromium-chromedriver`` Firefox
seems to come with webdriver out of the box on ubuntu.

Use the code below to test selenium and webdriver installation:

.. code:: python

   from selenium import webdriver
   import time
   driver = webdriver.Chrome() #or use another backend
   driver.maximize_window()
   driver.get('https://www.google.com')
   print('You have 10 secs to check the browser window...')
   time.sleep(10)

On other platforms find the easiest way to install selenium in your
environment.

Here some references:

-  https://www.seleniumhq.org/download/#thirdPartyDrivers
-  http://chromedriver.chromium.org/
-  https://github.com/mozilla/geckodriver/releases
-  [STRIKEOUT:PhantomJs] (abandoned)

Decompressed executables should be in your PATH. If you update python’s
``webdriver`` package make sure you update browsers and drivers.

Useful links for working with XPath
-----------------------------------

-  Xpath cheatsheets

   -  http://ricostacruz.com/cheatsheets/xpath.html
   -  https://web.archive.org/web/20200218033716/http://xpath.alephzarro.com/content/cheatsheet.html

-  Firefox addons

   -  https://addons.mozilla.org/es/firefox/addon/firebug/
   -  https://addons.mozilla.org/es/firefox/addon/firepath/

Killing processes hanging around
--------------------------------

Depending on your configuration from virtualdisplay and browser,
processes like:

::

   Xvnc
   Xvfb
   Xephyr
   chromedriver
   ...

may keep hanging around. You may want to kill them (on linux) with:

::

   # check the wanted process is alive
   ps faux | grep Xvnc
   # and you can kill it. If you are running as root, make sure you are not killing someone else's process too 
   pkill Xvnc

On other OS google on how to do it (on windows you can use the Task
Manager)

.. |.github/workflows/xpwd_ci.yml| image:: https://github.com/joaduo/xpathwebdriver/actions/workflows/xpwd_ci.yml/badge.svg
   :target: https://github.com/joaduo/xpathwebdriver/actions/workflows/xpwd_ci.yml



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/joaduo/xpathwebdriver",
    "name": "xpathwebdriver",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "testing, automation, web, unittest, webdriver, selenium, xpath, css",
    "author": "Joaquin Duo",
    "author_email": "joaduo@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/e7/af/f52fd159236268bc23db1c7935a74546ab2f60f5e55f19376bd70d8f2582/xpathwebdriver-2.0.6.tar.gz",
    "platform": null,
    "description": "xpathwebdriver\n==============\n\n|.github/workflows/xpwd_ci.yml|\n\nA python wrapper for interacting with Selenium through XPath and CSS\nselectors. You can now use XPaths like ``//div/text()``:\n\n.. code:: python\n\n   from xpathwebdriver.browser import Browser\n\n   browser = Browser()\n\n   # xpath returns text\n   for idx, t in enumerate(browser.select_xpath('//div/text()')):\n       print(idx, t)\n\n   # css selector returns elements\n   for idx, elem in enumerate(browser.select_css('.result__title')):\n       print(idx, elem.text)\n\nWhich will return you a string as expected. Something webdriver API\nmakes more complicated.\n\nMeans you can write all your tests based on XPath.\n\nAlso adds:\n\n-  Interactive shell for testing XPath manually and easily against a\n   live browser\n\n   -  You can share the interactive shell with a script, to keep track\n      of errors/debugging\n\n-  Multiple browser management\n-  Browser life management (whether to keep the browser open or kill it\n   on exit)\n\n   -  Management is done through python contexts (``with`` statement)\n\n-  Useful settings for local and remote (headless) testing\n\n   -  Also supports environment variables as settings\n   -  Plus allowing custom settings that you can also push through\n      environment variables\n\n-  Screenshots comparison and diff management\n-  Virtual display management (so you can run \u201cheadless\u201d in a remote\n   instance)\n\n   -  you can use VNC to access the remote Browser\n\n-  Adding ``xpath``, ``css``, ``selector`` methods to returned\n   ``WebElement`` objects, to keep the Xpath functionality\n\nUbuntu quick installation\n~~~~~~~~~~~~~~~~~~~~~~~~~\n\nYou can opt to use Chromium to simplify installation:\n\n::\n\n   sudo apt-get install -y python3-pip imagemagick findimagedupes tightvncserver xserver-xephyr xvfb unzip chromium-browser\n   # chromium-chromedriver (from 22.04 and on you no longer need to install this package, seems it's obsolete and comes with chromium itself)\n   sudo pip3 install xpathwebdriver Pillow ipython\n\nYou can quickly test it running:\n\n::\n\n   xpathshell\n\nThat will open an interactive shell with a browser object. Use TAB to\nautocomplete available API. Use ``browser.driver`` to directly access\nthe webdriver object.\n\nGeneral installation\n--------------------\n\n::\n\n   pip install xpathwebdriver\n\n1. Install xpathwebdriver using pip.\n2. Install google chrome.\n3. Download chromedriver for your Chrome version and install it in your\n   path. https://chromedriver.chromium.org/downloads\n4. That generally should work on a modern Linux System (not tested but\n   should also work on other oses). Try example in section below\n5. For image comparison install ``pip install Pillow``,\n   ``findimagedupes`` and ``imagemagick`` packages for your OS. (they\n   are not automatically installed to keep basic requirements low) On\n   ubuntu: ``sudo apt install imagemagick findimagedupes``\n6. For interactive shell install ``pip install ipython``\n\nCheck \u201cInstalling Selenium\u201d section for other browsers and details.\n\nExample\n-------\n\n.. code:: python\n\n   from xpathwebdriver.browser import Browser\n\n   browser = Browser()\n   browser.get_url('https://duckduckgo.com/')\n   browser.fill(\".//*[@id='search_form_input_homepage']\", 'xpathwebdriver\\n')\n   # Using xpath that returns text\n   for idx, t in enumerate(browser.select_xpath('//div/text()')):\n       print(idx, t)\n   # Using css selector which returns elements\n   for idx, elem in enumerate(browser.select_css('.result__title')):\n       print(idx, elem.text)\n\nDocumentation and tutorials\n---------------------------\n\n-  Check ``examples`` directory\n-  The ``BrowserAPI.md`` file has a quick list of Browser\u2019s API\n-  Use ``xpathsell -e`` to print available environment variables for\n   settings\n-  Use ``xpathsell --settings-help`` to print settings detailed\n   documentation\n\n   -  or optionally check ``xpathwebdriver/default_settings.py``\n\nIPython interactive shell\n-------------------------\n\nFirst install ipython ``pip install ipython`` (not installed to keep\nbasic requirements low) Run the ``xpathshell`` in your terminal, and you\nshould see something like:\n\n::\n\n   $ xpathshell\n   Python 3.7.5rc1 (default, Oct  8 2019, 16:47:45)\n   Type 'copyright', 'credits' or 'license' for more information\n   IPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help.\n\n   XpathBrowser in 'b' or 'browser' variables\n    Current url: data:,\n   In [1]: b.get('github.com/joaduo/xpathwebdriver/')\n   INFO 05:53:35:  Current url: https://github.com/joaduo/xpathwebdriver/\n\nFor a faster development and debugging cycles you can run an interactive\nshell which will let access the browser.\n\nOr pass the url in the command arguments. Eg:\n``xpathshell github.com/joaduo/xpathwebdriver/``\n\nInside IPython you can enter ``browser.select_xpath?`` to get\ndocumentation and can access API docs.\n\nMore ``XpathBrowser`` details at:\n\n-  https://github.com/joaduo/xpathwebdriver/blob/master/BrowserAPI.md\n-  https://github.com/joaduo/xpathwebdriver/blob/master/xpathwebdriver/xpath_browser.py\n-  https://github.com/joaduo/xpathwebdriver/blob/master/xpathwebdriver_tests/test_XpathBrowser.py\n\nUsing unittest library\n~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n   import unittest\n   from xpathwebdriver.webdriver_manager import get_browser\n\n   class SearchEnginesDemo(unittest.TestCase):\n       def test_duckduckgo(self):\n           with get_browser() as browser:\n               browser.get_url('https://duckduckgo.com/')\n               browser.fill('.//*[@id=\"search_form_input_homepage\"]', 'xpathwebdriver\\n')\n\nCheck a more options in the ``examples`` directory.\n\nInstalling Selenium\n-------------------\n\nUnder Ubuntu you should easily install Selenium/Webdrivar with\n``sudo apt install chromium-browser chromium-chromedriver`` Firefox\nseems to come with webdriver out of the box on ubuntu.\n\nUse the code below to test selenium and webdriver installation:\n\n.. code:: python\n\n   from selenium import webdriver\n   import time\n   driver = webdriver.Chrome() #or use another backend\n   driver.maximize_window()\n   driver.get('https://www.google.com')\n   print('You have 10 secs to check the browser window...')\n   time.sleep(10)\n\nOn other platforms find the easiest way to install selenium in your\nenvironment.\n\nHere some references:\n\n-  https://www.seleniumhq.org/download/#thirdPartyDrivers\n-  http://chromedriver.chromium.org/\n-  https://github.com/mozilla/geckodriver/releases\n-  [STRIKEOUT:PhantomJs] (abandoned)\n\nDecompressed executables should be in your PATH. If you update python\u2019s\n``webdriver`` package make sure you update browsers and drivers.\n\nUseful links for working with XPath\n-----------------------------------\n\n-  Xpath cheatsheets\n\n   -  http://ricostacruz.com/cheatsheets/xpath.html\n   -  https://web.archive.org/web/20200218033716/http://xpath.alephzarro.com/content/cheatsheet.html\n\n-  Firefox addons\n\n   -  https://addons.mozilla.org/es/firefox/addon/firebug/\n   -  https://addons.mozilla.org/es/firefox/addon/firepath/\n\nKilling processes hanging around\n--------------------------------\n\nDepending on your configuration from virtualdisplay and browser,\nprocesses like:\n\n::\n\n   Xvnc\n   Xvfb\n   Xephyr\n   chromedriver\n   ...\n\nmay keep hanging around. You may want to kill them (on linux) with:\n\n::\n\n   # check the wanted process is alive\n   ps faux | grep Xvnc\n   # and you can kill it. If you are running as root, make sure you are not killing someone else's process too \n   pkill Xvnc\n\nOn other OS google on how to do it (on windows you can use the Task\nManager)\n\n.. |.github/workflows/xpwd_ci.yml| image:: https://github.com/joaduo/xpathwebdriver/actions/workflows/xpwd_ci.yml/badge.svg\n   :target: https://github.com/joaduo/xpathwebdriver/actions/workflows/xpwd_ci.yml\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Selenium/webdriver wrapper for XPath and CSS selection",
    "version": "2.0.6",
    "project_urls": {
        "Homepage": "https://github.com/joaduo/xpathwebdriver"
    },
    "split_keywords": [
        "testing",
        " automation",
        " web",
        " unittest",
        " webdriver",
        " selenium",
        " xpath",
        " css"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e7aff52fd159236268bc23db1c7935a74546ab2f60f5e55f19376bd70d8f2582",
                "md5": "7ad6b5e40ace04d27abeb7a252edddb9",
                "sha256": "47c81feabea2c5e1bfa7001207fb380edce5d47dd7f90b1533c54b8ff3b6e0f1"
            },
            "downloads": -1,
            "filename": "xpathwebdriver-2.0.6.tar.gz",
            "has_sig": false,
            "md5_digest": "7ad6b5e40ace04d27abeb7a252edddb9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 32967,
            "upload_time": "2024-10-14T04:40:37",
            "upload_time_iso_8601": "2024-10-14T04:40:37.472351Z",
            "url": "https://files.pythonhosted.org/packages/e7/af/f52fd159236268bc23db1c7935a74546ab2f60f5e55f19376bd70d8f2582/xpathwebdriver-2.0.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-14 04:40:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "joaduo",
    "github_project": "xpathwebdriver",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [
        {
            "name": "pyvirtualdisplay",
            "specs": [
                [
                    ">=",
                    "0.2.1"
                ]
            ]
        },
        {
            "name": "selenium",
            "specs": [
                [
                    ">=",
                    "3.0.2"
                ]
            ]
        },
        {
            "name": "ipython",
            "specs": [
                [
                    ">=",
                    "5.8.0"
                ]
            ]
        },
        {
            "name": "Pillow",
            "specs": [
                [
                    ">=",
                    "6.2.1"
                ]
            ]
        },
        {
            "name": "parsel",
            "specs": [
                [
                    ">=",
                    "1.6.0"
                ]
            ]
        }
    ],
    "lcname": "xpathwebdriver"
}
        
Elapsed time: 8.06688s