# I want to automate this text field

**URL:** <https://www.ruby-forum.com/t/i-want-to-automate-this-text-field/166747>\
**Category:** Ruby\
**Created:** [April 29, 2009, 6:21am UTC](https://www.ruby-forum.com/t/i-want-to-automate-this-text-field/166747 "2009-04-29T06:21:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashacta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de053/32.png) [@ashacta](https://www.ruby-forum.com/u/ashacta)\
**Post date:** [April 29, 2009, 6:21am UTC](https://www.ruby-forum.com/t/i-want-to-automate-this-text-field/166747/1 "2009-04-29T06:21:24Z")

</div>

Hi

I want to automate this text field.

ie.text\_field(:name, “JMSText”).set(‘TEST’).

Instead of TEST i want to copy content from text file and paste it in  
text filed.

if i change the text in notepad …it shoudl take the new value

Pleae help regarding this

Regards  
Asha

---

<div class="post-metadata">

**Author:** ![ashacta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de053/32.png) [@ashacta](https://www.ruby-forum.com/u/ashacta)\
**Post date:** [April 29, 2009, 6:38am UTC](https://www.ruby-forum.com/t/i-want-to-automate-this-text-field/166747/2 "2009-04-29T06:38:22Z")

</div>

Asha Latha wrote:

> ie.text\_field(:name, “JMSText”).set(‘TEST’).
> 
> Instead of TEST i want to copy content from text file and paste it in  
> text filed.

Use the File::read() method:

file\_path = “path to your file.txt”

file\_contents = File.read(file\_path)

ie.text\_field(:name, “JMSText”).set(file\_contents)

> if i change the text in notepad …it shoudl take the new value

With the above approach, you must rerun your Ruby program after changing  
the text in notepad.

If you wish to have your Ruby program respond to changes in the text  
file while it is still running, then take a look at libinotify.

---

<div class="post-metadata">

**Author:** ![ashacta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de053/32.png) [@ashacta](https://www.ruby-forum.com/u/ashacta)\
**Post date:** [April 29, 2009, 7:37am UTC](https://www.ruby-forum.com/t/i-want-to-automate-this-text-field/166747/3 "2009-04-29T07:37:51Z")

</div>

Hi

Thanks its working.

But i want to read first line and then paste that one to text filed,  
once it is done i will read second line and so on…

Please help me to solve this.

Regards  
Asha

Suraj K. wrote:

> Asha Latha wrote:
> 
> > ie.text\_field(:name, “JMSText”).set(‘TEST’).
> > 
> > Instead of TEST i want to copy content from text file and paste it in  
> > text filed.
> 
> Use the File::read() method:
> 
> file\_path = “path to your file.txt”
> 
> file\_contents = File.read(file\_path)
> 
> ie.text\_field(:name, “JMSText”).set(file\_contents)
> 
> > if i change the text in notepad …it shoudl take the new value
> 
> With the above approach, you must rerun your Ruby program after changing  
> the text in notepad.
> 
> If you wish to have your Ruby program respond to changes in the text  
> file while it is still running, then take a look at libinotify.

---

<div class="post-metadata">

**Author:** ![ashacta](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/9de053/32.png) [@ashacta](https://www.ruby-forum.com/u/ashacta)\
**Post date:** [April 29, 2009, 8:15am UTC](https://www.ruby-forum.com/t/i-want-to-automate-this-text-field/166747/4 "2009-04-29T08:15:44Z")

</div>

Asha Latha wrote:

> Hi
> 
> Thanks its working.
> 
> But i want to read first line and then paste that one to text filed,  
> once it is done i will read second line and so on…
> 
> Please help me to solve this.
> 
> Regards  
> Asha

IO.foreach(“file\_name”) do |line|  
…stuff here  
end
