• If you are a Web automator, check XPantherIde App
, which is XPantherIDE
, combined with GUI in a executable file, to ease your work.
• If you are an Appium automator, or want to find xpath of xml documents, check XPanther
, which is part of xpanther package.
Check the latest release of this repo, or click here:
You might have to disable anti-virus if you can't download it due to being falsely detected as a virus.
or install package (check below) and paste this into terminal:
python -m xpanther.launch
XPanther captures the outerHTML of the element you click, compares it to every element in the web page using different methods to conclude anything unique. After finding unique attributes and relations, it forms all xpaths available. Then using Selenium, it starts checking every xpath if it works for the corresponding element and measures it's speed too. If all goes well, you should end up with a tested working xpath of the element you just clicked in moments!
It needs Administrator Rights for it to work because Selenium can't find the chrome.exe otherwise, and I didn't want to include chrome.exe binary inside the executable.
- Open and run the executable file.
- Enter the url of the website, and click start!
- Start
right-clicking
over elements, and an alert pop-up will show their xpath - When done, just close the browser.
- After closing, a output window will open, showing in a text file the output of the program, which are the xpath, the speed of xpath and language-specific Selenium code on how to find the elements.
Language
- Click on the dropdown and choose which programming language you want to be the Selenium code of finding the elementShow All
- Check it if you want all the xpaths' be shown, this is more tolerant and gives you more options. The default mode though is accurate, more strict and very sensitive to click placement, but might not give a xpath result due to last reason.
pip install xpanther
or search it by xpanther
if you have editor with package installer.
Import XPanther to your file like:
from xpanther import XPanther
If it doesn't show up (happens in pycharm sometimes), go to global site-packages (pip show xpanther
<--cmd command to find directory), find and copy xpanther package, and paste it to your project's venv.
- string,
- the path to any local text file you might have or
- a page url (check below for optional-parameter page_url).
- as a string
- or alternatively an integer, which represents the index of that element in the DOM, starting from 1 as the first.
XPanther(dom).capture(element)
After writing this , run the code and the xpath of that element should be returned as value and printed in the console.
-
xml
(default:False
): Set this toTrue
if document is not HTML, this is because the xml document can contain uppercase characters in attributes, unlike html, so a different parser needs to be used. -
pre_formatted
(default:False
): Set this toTrue
if you have already formatted document and don't want formatter of XPanther to change anything. -
url_input
(default:False
): Set this toTrue
if you intend to insert page url intead of text or file as the dom parameter of this class. -
child_method
(default:True
): Set this toFalse
if you don't want the Xpath to be found using its children, reason for this can depend on context. -
show_all
(default:False
): Set this toTrue
if you want all possible working xpaths found and not resort to only the one chosen by program. -
no_digits
(default:False
): Set this toTrue
if you don't want element attributes that contain numbers. -
print_output
(default:True
): Set this toFalse
if you don't want the program to print anything in console but just return the xpath as a value in any variable or function. -
speed
(default:'normal'
): other valid options are'fast'
-- (less detailed, faster execution),'slow'
-- (more detailed, slower execution), or an integer (maximum is 50, which represent the number of attributes of element program can take and proccess to find combinations of). if you have a slow computer, better set it to 'fast', cause it takes lesser number of combination and lowers memory and performance consumption, thus increasing speed of execution.
For most optimal usage, keep this values as default, you have to only change to xml=True if you are not dealing with HTML, and url_input=True if you like to fetch the HTML directly from link.
XPantherIDE
is a simple Selenium script, that tries to mimic an IDE for finding xpaths instantly on any web page with just 1 click.
Import:
from xpanther import XPantherIDE
Use:
XPantherIDE('page_url').start()