您需要调整脚本以查找并阅读验证电子邮件。以下可用于阅读电子邮件。根据电子邮件的复杂程度和收件箱的内容,您可能需要进行一些调整。
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
您将无法“点击”该链接。但是,它应该与在浏览器中导航到它相同 - 即让 watir 转到从电子邮件中提取的链接。
br = Watir::Browser.new :chrome
br.goto verification_link