Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. require 'rubygems'
  2. require 'capybara'
  3. require 'capybara/poltergeist'
  4. require 'phantomjs'
  5.  
  6. class HobbyKing
  7. def initialize
  8.  
  9. Capybara.register_driver :selenium do |app|
  10. #Capybara::Selenium::Driver.new(app)
  11. Capybara::Selenium::Driver.new(app, :browser => :firefox) # I used chrome
  12. end
  13. Capybara.javascript_driver = :selenium
  14. Capybara.default_selector = :css
  15. @session = Capybara::Session.new(:selenium)
  16. Capybara.default_wait_time = 10
  17.  
  18.  
  19.  
  20. @user = {email: 'adonnco@gmail.com', password: '147963'}
  21. @urls = File.foreach(ARGV[0]).map{|line| line.chomp}
  22. @phrase = ['my text here']
  23.  
  24.  
  25.  
  26. puts 'Script initialized'
  27.  
  28.  
  29. post_frazes
  30. sleep 1
  31.  
  32. end
  33.  
  34.  
  35.  
  36. def login(user)
  37. puts "Logging in #{user[:email]}"
  38. @session.visit 'https://hobbyking.com/en_us/customer/account/login'
  39.  
  40. sleep 1
  41.  
  42. @session.click_on('No Thanks')
  43. sleep 2
  44.  
  45. @session.fill_in 'login[username]', with: user[:email]
  46. @session.fill_in 'login[password]', with: user[:password]
  47. @session.click_button('send2')
  48.  
  49. sleep 1
  50.  
  51. end
  52.  
  53.  
  54. def post_frazes
  55.  
  56. puts 'Posting frazes'
  57. login(@user)
  58. @urls.each {|url| post_frazes2(url)}
  59.  
  60. sleep 1
  61. end
  62. end
  63.  
  64.  
  65. def post_frazes2(url)
  66.  
  67. @session.visit url
  68. sleep 1
  69. puts "Url -- #{url}"
  70.  
  71. @session.execute_script("$('tab2').click()");
  72.  
  73.  
  74.  
  75. if @session.has_text?('http://techexperience.net/go/') #this also doesn't work.
  76.  
  77. puts "Already posted here. Skipping!"
  78.  
  79. else
  80.  
  81. #print @session.html
  82. sleep 3
  83.  
  84. #@session.execute_script("$('required-entry validate-no-html-tags').fill_in('asddsf')");
  85.  
  86. @session.find('#comment')
  87.  
  88.  
  89. @session.fill_in 'comment', with: @phrase
  90.  
  91.  
  92.  
  93.  
  94. #@session.findElement(By.name("required-entry validate-no-html-tags")).click();
  95. #@session.findElement(By.name("required-entry validate-no-html-tags")).sendKeys(@phrase);
  96.  
  97. #@session.execute_script("$('required-entry validate-no-html-tags').show()")
  98.  
  99. #@session.execute_script ("$('required-entry validate-no-html-tags');" @session.fill_in, with: @frazes)
  100.  
  101. #text_area = @session.first(:css, 'required-entry validate-no-html-tags')
  102. #@session.text_area.fill_in('Test')
  103.  
  104.  
  105.  
  106. sleep 16
  107.  
  108.  
  109. end
  110. end
  111. robot = HobbyKing.new
  112. puts 'Done!'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement