title: Chrome Extensions - Click on element in actual page
body: <p>I'm trying to make a simple extension, that can click in a element on the my principal page, example: I have a login page that have 6 buttons to choose a password and I want to simulate a click in each button(I already did this on Selenium).</p>
  
  <p>But, when I use de DOM(document object) the chrome is getting the document from a new HTML and is not getting my HTML.</p>
  
  <p>Above my example:</p>
  
  <p><strong>background.js</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function checkForValidUrl(tabId, changeInfo, tab) {
      chrome.pageAction.show(tabId);
  }
  
  function getElementByXpath(path) {
    return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  }
  
  chrome.tabs.onUpdated.addListener(checkForValidUrl);
  
  chrome.pageAction.onClicked.addListener(function(tab) {
   var element = getElementByXpath("//label[contains(text(),'1')]");
      element.click();
  });</code></pre>
  </div>
  </div>
  </p>
  
  <p>On my code, when I try to select a Element I can't get the main page.</p>
  
  <p><strong>MANIFEST.js</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>{
    // Required
    "manifest_version": 2,
    "name": "Minha Extensão",
    "version": "2",
  
    // Recommended
    "description": "A plain text description",
    "icons": { "16": "icon-w-1.png",
             "48": "icon-w-2.png",
            "128": "icon-w-3.png" },
    "background": {
          "scripts": ["background.js"]
      },
      "page_action": {
          "default_icon": "icon-w-3.png"
      },
      "permissions": ["tabs", "http://*/*", "https://*/*"]        
  }</code></pre>
  </div>
  </div>
  </p>
  
  <p>My next step will be, in the moment that I click on the extension button, open a new window with buttons that when I click, can simulate a click on another button in the main page.</p>