vendredi 20 février 2015

Webdriver Javascript how to click a download button in a modal

I'm trying to build a node.js script that runs with node and logs into a website, navigates to a download section and clicks a download button.


The website is twitter, and the data is campaign data that is in a csv file.


I've hacked this together so my code won't be perfect or great.


I am basically at the last point where I need to click a downloadButton with the following 'Inspect Element' data:


Download


I cannot locate this html in the page source, only via 'Inspect Element' (Using chrome)


This code runs with: node chromedriver (in the folder) main.js packages.json


main.js: 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('http://ift.tt/1w54Rn3');

// 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 campaign of choice //
driver.findElement(webdriver.By.xpath("//form[@class=\"t1-form clearfix signin js-signin\"]//button[@class=\"submit btn primary-btn\"]")).click()

// Selects the calendar (to select timeframe) //
driver.findElement(webdriver.By.xpath("//form[@id=\"account-selector-form\"]/div[2]/ul/li[2]/a/img")).click();

// Selects a year ago of data //
driver.findElement(webdriver.By.xpath("//div//*[@id=\"dashboardBox\"]/form/div/div/span[2]")).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()


packages.json:



{
"name": "webdriver-recipes",
"private": true,
"devDependencies": {
"selenium-webdriver": "~2.42.1"
}
}


Thanks for the assist.


Aucun commentaire:

Enregistrer un commentaire