I am using Ruby with Watir to open irctc webpage. I can enter username and password automatically. When It comes to CAPTCHA, I can not use any syntax to enter a CAPTCHA. Because I do not know what it will be beforehand. I just want a simple method in which I can enter CAPTCHA by hand. While entering CAPTCHA my script should wait, then It should execute next syntax from script.
#require 'watir-webdriver'
require 'watir'
caps = Selenium::WebDriver::Remote::Capabilities.firefox
caps['acceptInsecureCerts'] = true
driver = Selenium::WebDriver.for(:firefox, desired_capabilities: caps)
browser = Watir::Browser.new(driver)
# text to show on console
puts "Beginning of the automation of IRCTC webpage"
browser.goto("https://www.irctc.co.in/eticketing/loginHome.jsf")
#browser.button(:id, "returnButton").click
#set a variable
search_text = "my_username"
#puts " Step 2: enter "+ search_text +" in the search text field."
browser.text_field(:name, "j_username").set search_text # "j_username" is the name of the search field
#browser.span(:class, "RveJvd snByac").click # "RveJvd snByac" is the class-name of the Search button
search_text = "my_password"
browser.text_field(:name, "j_password").set search_text
#Here I need to enter CAPTCHA before proceeding to next syntax.
browser.button(:type, "submit").click
There are 2 ways to manually enter data: 1. Add sleep command so you can manually enter Captcha to the browser by hand:
sleep 30
Add gets command that will prompt user to enter captcha via console (I do not know the actual name of the captcha field):
captcha = gets.chomp
browser.text_field(:name, "captcha").set captcha