2

I am trying to automate Google Soccer 2012, just for fun. I did not have any problems automating other Google games.

The problem with Soccer is that it does not react to left and right, but space works just fine.

This is the entire script:

puts "Go to game."
require "bundler/setup"
require "watir-webdriver"
browser = Watir::Browser.new :chrome
browser.goto "https://www.google.com/doodles/soccer-2012"

sleep 1
puts "Go!"
browser.div(id: "hplogo").frame.div.click

sleep 1
puts "Left!"
browser.send_keys :left

sleep 1
puts "Rigth!"
browser.send_keys :right

sleep 1
puts "Space!"
browser.send_keys :space

You can see code for Soccer and other games at https://github.com/zeljkofilipin/olympics

Anybody has an idea how to get left and right working?

2 Answers 2

1

The goalie kind of moves a little if you hit the arrow key many times:

100.times{browser.send_keys :left}

Which makes me think that you need to some how hold down the arrow key rather than just tapping it. Unfortunately I could not find a way to hold keys down (the selenium-webdriver action builder key_down seems to only allow control keys).

If you are okay with not using the keyboard, the goalie seems to respond well to the mouse:

def move(browser, direction)
    el = browser.driver.find_element(:id, 'hplogo')
    case direction
        when :start
            browser.driver.action.move_to(el).perform
        when :left
            browser.driver.action.move_by(-1, 0).perform
        when :left_fast
            browser.driver.action.move_by(-5, 0).perform            
        when :right
            browser.driver.action.move_by(1, 0).perform
        when :right_fast
            browser.driver.action.move_by(5, 0).perform         
        when :jump
            browser.send_keys :space
    end
end

puts "Go to game."
require "watir-webdriver"
browser = Watir::Browser.new :chrome
browser.goto "https://www.google.com/doodles/soccer-2012"

sleep 1
puts "Go!"
browser.div(id: "hplogo").frame.div.click
move(browser, :start) #Centre mouse

sleep 1
puts "Left!"
80.times{move(browser, :left)}

sleep 1
puts "Right!"
10.times{move(browser, :right_fast)}

sleep 1
puts "Space!"
move(browser, :jump)
0
0
sleep 3
puts "Left!"
browser.send_keys :left

you send the left and right keys too quickly. The animation doesn't seem to detect the input untill the animation has finished.

4
  • I do not think that is the problem. I have tried sending left/right from IRB after waiting for 10-20 seconds, it did not work. Does sending left/right work for you when you increase sleeps? Aug 10, 2012 at 10:16
  • yes it does... when I had it on 1 didn't work, on 3 worked. :/
    – Simon
    Aug 10, 2012 at 10:27
  • No, still does not work for me. Can you let me know your ruby, selenium-webdriver, watir-webdriver and chromedriver versions? (I have all the latest, on windows 7.) Aug 10, 2012 at 10:53
  • it seems to be hit and miss as went back to it after it worked and it doesn't always work. But yes, Ubuntu 12.04, ruby 1.9.3p194, latest version of watir-webdriver 0.6.1 and 2.25.0 of selenium. Chrome driver is the latest for 64 bit linux
    – Simon
    Aug 10, 2012 at 10:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.