Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
require "selenium-webdriver"
class ScratchLogger
def create_accounts(count, username, password)
1.upto(count).each do |i|
create_account("#{username}#{i}", "#{password}#{i}", "gcfcampus2016@gmail.com", "Styczeń", "2006")
end
end
private
def create_account(username, password, email, month, year)
driver = Selenium::WebDriver.for :chrome
driver.navigate.to 'http://scratch.mit.edu'
login = driver.find_element(:css, '.link.right.join a')
login.click
sleep(1)
driver.switch_to.frame(driver.find_element(:css, 'iframe'))
driver.execute_script("document.getElementsByClassName('username')[0].setAttribute('value', '#{username}')");
driver.execute_script("document.getElementsByClassName('password')[0].setAttribute('value', '#{password}')");
driver.execute_script("document.getElementsByClassName('password-confirm')[0].setAttribute('value', '#{password}')");
next_button = driver.find_element(:css, '#registration-next')
next_button.click
sleep(1)
driver.find_element(:css, '.birthmonth').send_keys(month)
driver.find_element(:css, '.birthyear').send_keys(year)
driver.find_element(:css, 'input[name="gender"]').click
driver.find_element(:css, '.country').send_keys("Poland")
next_button = driver.find_element(:css, '#registration-next')
next_button.click
sleep(1)
driver.execute_script("document.getElementsByClassName('email')[0].setAttribute('value', '#{email}')");
driver.execute_script("document.getElementsByClassName('email-confirm')[0].setAttribute('value', '#{email}')");
next_button = driver.find_element(:css, '#registration-next')
next_button.click
sleep(5)
driver.close
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment