1

私は Watir が初めてで、それを学んでいます。学習のために、登録を行うスクリプトを開発しましたが、登録を完了するには、GMAIL アカウントで送信されたメールを確認する必要があります。そこで、ruby GMAIL gem をインストールし、github のチュートリアルを実行して、以下のサンプル スクリプトを作成しました。

require "watir-webdriver"
require "gmail"
br = Watir::Browser.new :chrome
br.goto "gmail.com"
gmail = Gmail.new("sample@registration.com", "111111")
gmail.inbox.count(:unread)
gmail.inbox.click(:unread, :from => "noreply@registration.com").label("Confirm Verification")

しかし、スクリプトが機能していないため、エラーの可能性と、メールにアクセスして確認リンクをクリックする方法を教えてください。

4

1 に答える 1

2

確認メールを見つけて読むには、スクリプトを調整する必要があります。以下は、電子メールを読むために使用できます。メールの複雑さと受信トレイの内容によっては、いくつかの調整が必要になる場合があります。

verification_link = ''
Gmail.new("sample@registration.com", "111111") do |gmail|
    #Get the email the first email that is:
    #  unread and 
    #  from 'noreply@registration.com'
    email = gmail.inbox.emails(:unread, :from => 'noreply@registration.com').first

    #Get the message body, which will be in html
    message = email.body.decoded

    #Parse the message body for the link
    #  You may need to adjust the regex depending on the complexity of the email
    #  If the email is very complex, use Nokogiri to parse the html 
    verification_link = /<a.*?href="(.+?)".*?>Verify Now<\/a>/m.match(message)[1].gsub(/\s/, '')
    #=> "http://innovify.in/kwexcui/index.php?r=site/registerFirstSlap/key/3f21f205d603ce83e4dbd4667ff66a1f:2a/id/MTI2ODg2NjM4NTUyNw/lng/eng/email/maulik.goswami@bypeopletechnologies.in/companyName/R09PR0xFIFVLIExJTUlURUQ=/phoneNumber/012345678901234"
end

リンクを「クリック」することはできません。ただし、ブラウザでナビゲートするのと同じである必要があります。つまり、電子メールから抽出されたリンクに移動します。

br = Watir::Browser.new :chrome
br.goto verification_link
于 2013-07-11T03:23:55.300 に答える