Created
January 23, 2014 07:19
-
-
Save Martin91/8574332 to your computer and use it in GitHub Desktop.
Use selenium web driver to add new tracking IDs for amazon's affiliate
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'selenium-webdriver' | |
ASSOCIATE_ACCOUNT = { email: '[email protected]', password: 'password' } | |
TRACKING_IDS_SUFFIX = 1..100 # By default, only 100 trackings IDs is supported | |
TRACKING_IDS_PREFIX = 'tracking_id' # Whatever unique characters you like | |
driver = Selenium::WebDriver.for :firefox | |
driver.navigate.to 'https://affiliate-program.amazon.com/' | |
# Fill in the account's email | |
driver.find_element(:id, 'username').send_keys ASSOCIATE_ACCOUNT[:email] | |
# Fill in the account's password | |
driver.find_element(:id, 'password').send_keys ASSOCIATE_ACCOUNT[:password] | |
driver.find_element(:name, 'sign_in').submit | |
TRACKING_IDS_SUFFIX.each do |tracking_id| | |
# Start to add new tracking id | |
driver.navigate.to 'https://affiliate-program.amazon.com/gp/associates/network/your-account/add-tracking-ids.html' | |
driver.find_element(:name, 'requestId').send_keys "#{TRACKING_IDS_PREFIX}#{tracking_id}" | |
driver.find_element(:id, 'add_tracking_id').submit | |
begin | |
# Find "Continue" button, which specifies that the expected tracking id is available | |
driver.find_element(:partial_link_text, '<img src="https://images-na.ssl-images-amazon.com/images/G/01/associates/storebuilder/continue-md-pri._V192207708_.gif" width="85" alt="Continue" height="22" border="0">').click | |
rescue Selenium::WebDriver::Error::NoSuchElementError => e | |
next | |
end | |
end | |
# Lastly signout and close the window | |
driver.find_element(:link_text, 'sign out').click | |
driver.quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment