How would I check to see if the correct text was input into the text box?
My code is:
element = driver.find_element :id => "gmail-sign-in"
element.click
element = driver.find_element :id => "Email"
element.send_keys "exampletestemail2903@gmail.com"
input = wait.until {
element = driver.find_element :id => "Email"
element if element.displayed?
}
input.send_keys("exampletestemail2903@gmail.com")
if input == "exampletestemail2903@gmail.com"
puts 'Correct Input'
else
puts 'Wong Input'
end
For example, I have this to check if the input text is correct, however, it prints the else
message even though the input is correct.
Can someone explain why?
It looks like you are trying to verify that send_keys is working correctly. That is unless there is some other action that could change the field you are entering text into after the text has been entered. As for the reason that your if block is always going to the else is that you are comparing an element to a string. The if block should be changed to the following to compare a string to a string:
if input.text == "exampletestemail2903@gmail.com"
That should fix the if block to be functioning as you expect.
You need to verify text in textbox to assert its value
element = driver.find_element :id => "gmail-sign-in"
element.click
element = driver.find_element :id => "Email"
element.send_keys "exampletestemail2903@gmail.com"
input = wait.until {
element = driver.find_element :id => "Email"
element if element.displayed?
}
input.send_keys("exampletestemail2903@gmail.com")
if input.text == "exampletestemail2903@gmail.com"
puts 'Correct Input'
else
puts 'Wong Input'
end
Hope this Helps :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.