Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Empty a Gmail label with FireWatir (See related posts)

When you have a huge label with thousands of messages, Gmail can't handle deleting all of them at a time (it says it can, but for me it's never worked). This solves the problem.

I wrote it more as a practice to get familiar with FireWatir, so it's not very pretty or anything and it's a bit slow. If you have doubts on how to use or suggestions on how to improve it please feel free to contact me.

By the way, it assumes Gmail is in German. Replace that string with the one that comes up for your language.

def empty_label(label)
  # you need a Firefox instance already running with JSSh installed and listening
  ff = Firefox.new
  # Goes to Gmail in HTML
  ff.goto('http://mail.google.com/mail/h/x4odcwnm5f5v/?s=l&l=#{label}')
  a = []
  # doing 'c.set' didn't work for me here so I had to do this hack of getting the value
  # and then acquiring the element thorugh ff.checkbox(:value,value)
  ff.checkboxes.each {|c| a << c.value}

  while a.length > 0 do
    c = []
    a.each {|v| c << ff.checkbox(:value,v)}
    # checks all checkboxes
    c.each {|e| e.set}
    # clicks the drop-down entry for deleting
    ff.select_list(:name,'tact').select('In den Papierkorb verschieben')
    ff.button(:name,'nvp_tbu_go').click
    a = []
    ff.checkboxes.each {|c| a << c.value}
  end
end

You need to create an account or log in to post comments to this site.


Click here to browse all 4858 code snippets

Related Posts