Device Device - 1 year ago 123
Javascript Question

Add XPath to chrome extension or into javascript

I'm making chrome extension and i need to have xpath in it, it dose not work even when i add jquery in to the manifest.


Uncaught ReferenceError: $x is not defined


"permissions": [
"content_scripts": [
"matches": ["*"],
"js": ["jquery-1.11.3.min.js", "Script.js"]


$x("//div[@class='nazevprdiv' and ./a[text()='"+name+"']]/../../td/table/tbody/tr[@class='detznamka']/td");

Answer Source

Like adelphus said, it's only a variable usd by Firebug as an xpath shortcut. You can implement it with this code:

function $x(path){
 var xpath = document.evaluate(path, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
   var temp = [];
   for (var i = xpath.snapshotLength - 1; i >= 0; i--) {
   return temp;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download