title: Webdriver Javascript how to click a download button in a modal
body: <p>I'm trying to build a node.js script that runs with chromedriver and selenium-webdriver: logs into a website, navigates to a download section and clicks a download button.</p>
  
  <p>The website is twitter, and the data is campaign data that is in a csv file.</p>
  
  <p>I've hacked this together so my code won't be perfect or great.</p>
  
  <p>I am basically at the last point where I need to click a downloadButton with the following 'Inspect Element' data:</p>
  
  <pre><code>&lt;button id="downloadButton" class="btn btn-primary"&gt;Download&lt;/button&gt;
  </code></pre>
  
  <p>I cannot locate this html in the page source, only via 'Inspect Element' (Using chrome)</p>
  
  <p>main.js:</p>
  
  <pre><code>var webdriver = require('selenium-webdriver');
  var driver = new webdriver.Builder().
  withCapabilities(webdriver.Capabilities.chrome()).
  build();
  
  username = "username"
  password = "password"
  
  driver.manage().timeouts().implicitlyWait(30000);
  
  // Navigate to Twitter ads login page //
  driver.get('https://twitter.com/login?redirect_after_login=https%3A%2F%2Fads.twitter.com%2F');
  
  // Enters a username into the username box //
  driver.findElement(webdriver.By.xpath("//form[@class=\"t1-form clearfix signin js-signin\"]//input[@name=\"session[username_or_email]\"]")).sendKeys(username);
  
  // Enters a password into a password box //
  driver.findElement(webdriver.By.xpath("//form[@class=\"t1-form clearfix signin js-signin\"]//input[@name=\"session[password]\"]")).sendKeys(password);
  
  //Clicks the sign in button
  driver.findElement(webdriver.By.xpath("//form[@class=\"t1-form clearfix signin js-signin\"]//button[@class=\"submit btn primary-btn\"]")).click()
  
  //Clicks the campaign of choice //
  driver.findElement(webdriver.By.xpath("//form[@id=\"account-selector-form\"]/div[2]/ul/li[2]/a/img")).click();
  
  // Selects the calendar // 
  driver.findElement(webdriver.By.xpath("//div//*[@id=\"dashboardBox\"]/form/div/div/span[2]")).click();
  
  //Click on year of data //
  driver.findElement(webdriver.By.xpath("//div[7]/div[4]/ul/li[6]")).click();
  
  //Clicks the export button // 
  driver.findElement(webdriver.By.xpath("//div//*[@id=\"dashboard-header\"]/div/div/div/button/span")).click();
  
  //This bit doesnt work: //
  driver.findElement(webdriver.By.id("downloadButton")).click()
  </code></pre>
  
  <p>packages.json:</p>
  
  <pre><code>{
    "name": "webdriver-recipes",
    "private": true,
    "devDependencies": {
      "selenium-webdriver": "~2.42.1"
    }
  }
  </code></pre>
  
  <p>Thanks for the assist.</p>