{"id":25438878,"url":"https://github.com/joaduo/xpathwebdriver","last_synced_at":"2025-11-01T08:30:34.851Z","repository":{"id":15185825,"uuid":"61451445","full_name":"joaduo/xpathwebdriver","owner":"joaduo","description":"Python Xpath Selenium Webdriver library. Making it easier to write Webdriver tests.","archived":false,"fork":false,"pushed_at":"2024-10-14T04:40:24.000Z","size":1097,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-14T15:14:13.354Z","etag":null,"topics":["ipython","selenium-python","webdriver","xpath"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joaduo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-06-18T20:34:16.000Z","updated_at":"2024-10-14T04:40:27.000Z","dependencies_parsed_at":"2024-09-14T01:31:38.421Z","dependency_job_id":"04d838fc-d037-4478-af9f-736ccb1cddc5","html_url":"https://github.com/joaduo/xpathwebdriver","commit_stats":{"total_commits":225,"total_committers":2,"mean_commits":112.5,"dds":0.01777777777777778,"last_synced_commit":"6e6f69b9a866555a9f9a0d894bacb857576672da"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joaduo%2Fxpathwebdriver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joaduo%2Fxpathwebdriver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joaduo%2Fxpathwebdriver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joaduo%2Fxpathwebdriver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joaduo","download_url":"https://codeload.github.com/joaduo/xpathwebdriver/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239136630,"owners_count":19587844,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ipython","selenium-python","webdriver","xpath"],"created_at":"2025-02-17T10:16:29.010Z","updated_at":"2025-11-01T08:30:34.789Z","avatar_url":"https://github.com/joaduo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# xpathwebdriver\n\n\n[![.github/workflows/xpwd_ci.yml](https://github.com/joaduo/xpathwebdriver/actions/workflows/xpwd_ci.yml/badge.svg)](https://github.com/joaduo/xpathwebdriver/actions/workflows/xpwd_ci.yml)\n\nA python wrapper for interacting with Selenium through XPath and CSS selectors.\nYou can now use XPaths like `//div/text()`:\n\n```python\nfrom xpathwebdriver.browser import Browser\n\nbrowser = Browser()\n\n# xpath returns text\nfor idx, t in enumerate(browser.select_xpath('//div/text()')):\n    print(idx, t)\n\n# css selector returns elements\nfor idx, elem in enumerate(browser.select_css('.result__title')):\n    print(idx, elem.text)\n```\n\nWhich will return you a string as expected. Something webdriver API makes 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 live browser\n  - You can share the interactive shell with a script, to keep track of errors/debugging\n- Multiple browser management\n- Browser life management (whether to keep the browser open or kill it on exit)\n  - Management is done through python contexts (`with` statement) \n- Useful settings for local and remote (headless) testing\n  - Also supports environment variables as settings\n  - Plus allowing custom settings that you can also push through environment variables\n- Screenshots comparison and diff management\n- Virtual display management (so you can run \"headless\" in a remote instance)\n  - you can use VNC to access the remote Browser\n- Adding `xpath`, `css`, `selector` methods to returned `WebElement` objects, to keep the Xpath functionality\n\n### Ubuntu quick installation\n\nYou can opt to use Chromium to simplify installation:\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    xpathshell\n\nThat will open an interactive shell with a browser object. Use TAB to autocomplete available API. Use `browser.driver` to directly access the webdriver object.\n\n## General installation\n\n```\npip install xpathwebdriver\n```\n\n1. Install xpathwebdriver using pip.\n2. Install google chrome.\n3. Download chromedriver for your Chrome version and install it in your path.\n   https://chromedriver.chromium.org/downloads\n4. That generally should work on a modern Linux System (not tested but should also work on other oses).\n   Try example in section below\n5. For image comparison install `pip install Pillow`,  `findimagedupes` and `imagemagick` packages for your OS. (they are not automatically installed to keep basic requirements low)\n   On ubuntu: `sudo apt install imagemagick findimagedupes`\n6. For interactive shell install `pip install ipython`\n\nCheck \"Installing Selenium\" section for other browsers and details.\n\n## Example\n\n```python\nfrom xpathwebdriver.browser import Browser\n\nbrowser = Browser()\nbrowser.get_url('https://duckduckgo.com/')\nbrowser.fill(\".//*[@id='search_form_input_homepage']\", 'xpathwebdriver\\n')\n# Using xpath that returns text\nfor idx, t in enumerate(browser.select_xpath('//div/text()')):\n    print(idx, t)\n# Using css selector which returns elements\nfor idx, elem in enumerate(browser.select_css('.result__title')):\n    print(idx, elem.text)\n```\n\n## Documentation and tutorials\n\n* Check `examples` directory\n* The `BrowserAPI.md` file has a quick list of Browser's API\n* Use `xpathsell -e` to print available environment variables for settings\n* Use `xpathsell --settings-help` to print settings detailed documentation\n  - or optionally check `xpathwebdriver/default_settings.py`\n\n## IPython interactive shell\n\nFirst install ipython `pip install ipython` (not installed to keep basic requirements low)\nRun the `xpathshell` in your terminal, and you should see something like:\n\n```\n$ xpathshell\nPython 3.7.5rc1 (default, Oct  8 2019, 16:47:45)\nType 'copyright', 'credits' or 'license' for more information\nIPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help.\n\nXpathBrowser in 'b' or 'browser' variables\n Current url: data:,\nIn [1]: b.get('github.com/joaduo/xpathwebdriver/')\nINFO 05:53:35:  Current url: https://github.com/joaduo/xpathwebdriver/\n\n```\n\nFor a faster development and debugging cycles you can run an interactive shell which will let access the browser. \n\nOr pass the url in the command arguments. Eg: `xpathshell github.com/joaduo/xpathwebdriver/`\n\nInside IPython you can enter `browser.select_xpath?` to get documentation 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\n### Using unittest library\n\n\n```python\nimport unittest\nfrom xpathwebdriver.webdriver_manager import get_browser\n\nclass 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```\n\nCheck a more options in the `examples` directory.\n\n## Installing Selenium\n\nUnder Ubuntu you should easily install Selenium/Webdrivar with `sudo apt install chromium-browser chromium-chromedriver`\nFirefox seems to come with webdriver out of the box on ubuntu.\n\nUse the code below to test selenium and webdriver installation:\n\n```python\nfrom selenium import webdriver\nimport time\ndriver = webdriver.Chrome() #or use another backend\ndriver.maximize_window()\ndriver.get('https://www.google.com')\nprint('You have 10 secs to check the browser window...')\ntime.sleep(10)\n```\n\nOn other platforms find the easiest way to install selenium in your environment.\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* ~~PhantomJs~~ (abandoned)\n\nDecompressed executables should be in your PATH.\nIf you update python's `webdriver` package make sure you update browsers and drivers.\n\n## Useful links for working with XPath\n\n* Xpath cheatsheets\n  * http://ricostacruz.com/cheatsheets/xpath.html\n  * https://web.archive.org/web/20200218033716/http://xpath.alephzarro.com/content/cheatsheet.html\n* Firefox addons\n  * https://addons.mozilla.org/es/firefox/addon/firebug/\n  * https://addons.mozilla.org/es/firefox/addon/firepath/\n\n## Killing processes hanging around\nDepending on your configuration from virtualdisplay and browser, processes like:\n\n```\nXvnc\nXvfb\nXephyr\nchromedriver\n...\n```\n\nmay keep hanging around. You may want to kill them (on linux) with:\n\n```\n# check the wanted process is alive\nps 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 \npkill Xvnc\n```\n\nOn other OS google on how to do it (on windows you can use the Task Manager)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoaduo%2Fxpathwebdriver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoaduo%2Fxpathwebdriver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoaduo%2Fxpathwebdriver/lists"}