how to get text

0 votes
hello , I have written this code in selenium ruby. what i want to do is to check whether name contain only aphabate and space.

now problem here is when i call user_FName("kabir3$4") .. kabir3$4  will go to send_keys (line4) and also in  

 val =f_name.attribute('value')  (line5,)   val should be val=kabir3$4 so that    if val=~/[^a-zA-Z\s]/  bolck give "Invalid user name "

message but this is no happening when i print val is gives "kabir" only . what ever name i pass with or without  any special character everything is accepted .

why after f_name.attribute('value')  fname changes .why?

also i tried to print   f_name.send_keys(fname).text  it gives nothing blank..why ??

 #Validation for First Name
1.  def user_FName(fname)    
2.   f_name= @driver.find_element(:id, 'first_name')
3.     puts"#{fname}"                                  //"kabir3$4
4.     f_name.send_keys(fname);                                       #f_name.send_keys(fname).text
5.     val =f_name.attribute('value')
6.     puts "val = #{val}"                                    //"kabir
7.     wait =Selenium::WebDriver::Wait.new(:timeout=>30)
8.    if (val.empty?)
9.       puts "User Name Field can't be Blank"
10.     elsif val.length>3&&val.length<=20
11.           if val=~/[^a-zA-Z\s]/

12             puts "Invalid User NAme: #{val}"
13            else puts "first name working fine!!"
 14           end    
 15       else puts"max lenght can 20 character "
16        end
17   end  
18   user_FName("kabir3$4")
Aug 23, 2023 in Selenium by SEEMA
• 110 points

edited Mar 5 33 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP