Package: xpanther
XPantherOverviewFind Unique Xpath expressions of HTML/XML elements.Mostly intended for Selenium and Appium automators.• If you are a Web automator, checkXPantherIde App, which isXPantherIDE, 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, checkXPanther, which is part of xpanther package.Table of content:XPantherIDE AppHow to downloadHow it worksHow to useOptionsXPanther packageHow to installXPantherHow to useOptionsXPantherIDEHow to useXPantherIDE AppHow to download:Check the latest release of this repo, or click here:Download XPantherYou 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-mxpanther.launchHow it works: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 atested working xpathof 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.How to use:Open and run the executable file.Enter the url of the website, and click start!Startright-clickingover elements, and an alert pop-up will show their xpathWhen 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.Options: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.XPanther packageThis package contains 2 modules,XPantherandXPantherIDEHow to install:pipinstallxpantheror search it byxpantherif you have editor with package installer.XPantherImport XPanther to your file like:fromxpantherimportXPantherIf 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.How to use:Insert insideXPanther()the wholeHTML/XMLtext, which can be in the form of:string,thepathto any local text file you might have ora pageurl(check below for optional-parameter page_url).Insert inside.capture()theouterHTML/wholetext of element to be found:as astringor alternatively aninteger, 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 thexpathof that element should be returned as value and printed in the console.Options:The class has a few optional-parameters that you can change to modify it in the way you want:xml(default:False): Set this toTrueif 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 toTrueif you have already formatted document and don't want formatter of XPanther to change anything.url_input(default:False): Set this toTrueif you intend to insert page url intead of text or file as the dom parameter of this class.child_method(default:True): Set this toFalseif 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 toTrueif you want all possible working xpaths found and not resort to only the one chosen by program.no_digits(default:False): Set this toTrueif you don't want element attributes that contain numbers.print_output(default:True): Set this toFalseif 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.XPantherIDEXPantherIDEis a simple Selenium script, that tries to mimic an IDE for finding xpaths instantly on any web page with just 1 click.Import:fromxpantherimportXPantherIDEUse:XPantherIDE('page_url').start()How to use:After you run the program, the browser will open, and you can start finding xpaths byright-clickingover elements. A pop up alert will appear showing the xpath, you must accept/close the alert before trying again. You can then just close the browser and the program terminates correctly.The program will test each xpath if it works, it is corresponding to clicked element, and output it in the console along with its speed.This repository is open to improvements and new ideas