-2

i need some help related to masked field in web form. Syntax of phone field is (___)___-_____, if i execute this code in ruby shell

browser.text_field(:id => 'txtphone').set '7893457889'

... nothing has been added in the phone field. then i find this solution in one blog, someone said first unmask this field using this code.

browser.text_field(:id,'txtphone').fire_event("unmask")

then write the above code again.

browser.text_field(:id => 'txtphone').set '7893457889'

but still nothing has happened. kindly help me out...am i doing right or still there is a mistake.

Željko Filipin
  • 56,372
  • 28
  • 94
  • 125
  • Please provide relevant HTML or link to the page, if it is public. – Željko Filipin Oct 06 '11 at 08:32
  • I think you are referring to this question http://stackoverflow.com/questions/6221417/setting-a-text-field-that-has-a-jquery-mask-on-it but frankly I'm not sure the stated 'solution' is really a solution since I've never seen a browser fire an event named 'unmask' Also the OP indicated that the script worked when run in IRB.. I think perhaps all that was happening was that adding that code allowed enough time for client side code to process before he tried to set the field, that it worked. I'd try making this work via IRB first, then see if the code works at full speed. may be timing issue – Chuck van der Linden Oct 07 '11 at 07:06
  • Downticked for never responding to requests for the HTML, and instead posting a duplicate question http://stackoverflow.com/questions/7845739/masked-text-box-issue. – Chuck van der Linden Oct 27 '11 at 19:20

1 Answers1

0

If you could provide some sample of the page HTML it will be easier to give you an answer more likely to work.

Given what you have provided us to work from, we have to go with the normal way that such masked input fields typically work and go from there. Usually pages with this kind of thing are calling a javascript function which is triggered by a specific event. Most often this is an event such as onchange but it may be something like keypress or any other even that happens when a normal user types or pasts text into the cell.

You likely need to experiment with using the '.fire_event' method to fire the proper javascript event, or if that fails entirely making a direct call to execute the proper script

When doing this do not confuse the name of a script such as 'applymask' or somesuch with the javascript event which causes that script to be invoked.

The answers to this question How to find out which JavaScript events fired? include some good information on how to use firebug or the chrome developer tools to figure out what events are being fired when you interact with an object on the browser screen.

Update: instead of responding here to indicate if this answer was of any use the OP reposted their question here Masked Text Box issue and by digging around on the vendor's demo site (since that time he actually had posted some of the HTML when we asked for it) I was able to find a solution using watir-webdriver that worked for him.

Community
  • 1
  • 1
Chuck van der Linden
  • 6,660
  • 2
  • 28
  • 43