# Question on watir

**URL:** <https://www.ruby-forum.com/t/question-on-watir/224437>\
**Category:** Ruby\
**Created:** [November 12, 2012, 5:45am UTC](https://www.ruby-forum.com/t/question-on-watir/224437 "2012-11-12T05:45:39Z")\
**Posts on this page:** 20\
**Page:** 9

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [March 28, 2013, 9:48am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/161 "2013-03-28T09:48:59Z")

</div>

> I want to be an order  
> the way they are situated in screen, Is it possible to get like that?
> 
> RAJ

There are some ideas on sorting IDs here, you should be able to collect  
the objects using the loop and then sort them using one of these sorting  
methods.  
[http://stackoverflow.com/questions/830155/nokogiri-sort-array-of-ids-according-to-order-in-html-document](http://stackoverflow.com/questions/830155/nokogiri-sort-array-of-ids-according-to-order-in-html-document)

textbox and textarea are both covered by text\_field. If you specifically  
want a textarea, use textarea.

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [March 28, 2013, 9:56am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/162 "2013-03-28T09:56:45Z")

</div>

No no i am not asking about the sorted one, But the order the objects  
are placed in the webpage,

For an example,

textbox(id : a) combobox(id :z) textbox(id : b)

now it has to print the id  
a  
z  
b.

But what it actually doing is,it print the textbox id first,and then it  
print the combobox id like  
a  
b  
z

But I want the first order  
azb.

Can you bring this?

RAJ

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [March 28, 2013, 10:07am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/163 "2013-03-28T10:07:16Z")

</div>

As I said,

Collect the objects in the initial loop.

Sort the collection of objects based on their position in the page using  
one of the methods given in the link, or create your own approach using  
the ideas on that page.

Then iterate through your sorted collection, happy in the knowledge that  
they are now in page order.

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [March 29, 2013, 12:04pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/164 "2013-03-29T12:04:43Z")

</div>

Hi, Have you ever used the test-factory? If so, can you tell me how it  
helps to our testing?

RAJ

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [March 29, 2013, 5:57pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/165 "2013-03-29T17:57:51Z")

</div>

Never used it. It looks interesting though, I’ll have a look.

At a glance I’d say that if you learn how to use it you’ll save yourself  
some time writing test scripts.

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [March 29, 2013, 11:37pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/166 "2013-03-29T23:37:43Z")

</div>

Am 29.03.2013 12:04, schrieb Raj pal:

> Hi, Have you ever used the test-factory? If so, can you tell me how it  
> helps to our testing?
> 
> RAJ

Please start a different thread for questions that are not related.

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [March 30, 2013, 4:30pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/167 "2013-03-30T16:30:24Z")

</div>

Never used it. It looks interesting though, I’ll have a look.

At a glance I’d say that if you learn how to use it you’ll save yourself  
some time writing test scripts.

Ok Thank you, and I will start a new thread.

RAJ

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [March 28, 2013, 11:32am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/168 "2013-03-28T11:32:31Z")

</div>

OK  
THANKS

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 3, 2013, 2:30pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/169 "2013-04-03T14:30:38Z")

</div>

hi,

Ruby has any Date validation function? Or do you have any function for  
date validation?

RAJ

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 3, 2013, 4:16pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/170 "2013-04-03T16:16:42Z")

</div>

I don’t know exactly what you mean by date validation, but Ruby has  
this:

require ‘date’  
Date.today  
Date.new( 2013, 4, 3 )

etcetera…

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 4, 2013, 11:27am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/171 "2013-04-04T11:27:27Z")

</div>

hi,

what I meant was, in the date field, I should not enter “raja”, if i  
enter it has to print on the console ,it’s not valid date.

RAJ

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 4, 2013, 11:47am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/172 "2013-04-04T11:47:32Z")

</div>

It depends whether you mean a Date object or a string in date format. If  
you want to validate I tend to use Regexp for that sort of thing.

Here’s a Regexp example which covers a variety of date-string formats:

> **[Rubular](https://rubular.com/r/SXfDou7sQs)**
>
> Ruby-based regular expression editor/tester

use like this:

if my\_date !~ /\d{1,2}[-/]\d{1,2}[-/]\d{4}/  
fail TypeError, 'Invalid date: ’ + my\_date  
end

For a Date object it’s just:

my\_date.is\_a?( Date )

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 4, 2013, 11:31am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/173 "2013-04-04T11:31:13Z")

</div>

hi,

the gmail,

If i have to automate the gmail account, then I will write the code like

begin  
$browser.text\_field(:id,‘Gmail’).set(‘raja’)  
rescue =\>e  
puts e.message  
puts e.backtrace  
end

begin  
$browser.text\_field(:id,‘password’).set(‘raja’)  
rescue =\>e  
puts e.message  
puts e.backtrace  
end

Likewise, if i have to automate 1000field, then it would 4000 lines of  
code, Is there any way could I able to put into the loop. My problem is,  
i couldn’t able to synchronize the id and value.Do you have any solution  
for this?

RAJ

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 4, 2013, 11:52am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/174 "2013-04-04T11:52:48Z")

</div>

Ok thank you.  
RAJ

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 4, 2013, 11:58am UTC](https://www.ruby-forum.com/t/question-on-watir/224437/175 "2013-04-04T11:58:29Z")

</div>

Raj pal wrote in post #1104349:

> if i have to automate 1000field, then it would 4000 lines of  
> code, Is there any way could I able to put into the loop. My problem is,  
> i couldn’t able to synchronize the id and value.Do you have any solution  
> for this?

Something like this should work.

my\_hash = {  
User1: ‘Pass1’,  
User2: ‘Pass2’  
}

my\_hash.each do |username, password|  
$browser.text\_field(:id,‘Email’).set(username.to\_s)  
$browser.text\_field(:id,‘Passwd’).set(password)  
#Other stuff here…  
end

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 4, 2013, 12:34pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/176 "2013-04-04T12:34:46Z")

</div>

hi Is there any way can I focus on to the text box through the program,  
More closely put,I have to bring cursor pointer to the specific textbox.

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 4, 2013, 12:28pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/177 "2013-04-04T12:28:52Z")

</div>

OK thank you.

RAJ

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 4, 2013, 12:47pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/178 "2013-04-04T12:47:02Z")

</div>

Can you explain what you’re trying to achieve by this? It’s sometimes  
convenient for Watir not to steal focus, and I don’t think this is how  
it operates; so is this your end-goal, or a stepping stone towards  
something else?

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 4, 2013, 1:08pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/179 "2013-04-04T13:08:52Z")

</div>

i have written a code to dynamically generate the id,but i don’t have to  
make that sychronise into the column in the spread sheet. so I decided  
to enter the value manually. So if I know the corresponding textbox,  
then i will enter the value manually and then full code will be  
generated,

look at this example,  
b.text\_field(:id,‘generated dynamically’).set(entered manually)

RAJ

---

<div class="post-metadata">

**Author:** ![rganapathy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/ee7513/32.png) [@rganapathy](https://www.ruby-forum.com/u/rganapathy)\
**Post date:** [April 4, 2013, 1:22pm UTC](https://www.ruby-forum.com/t/question-on-watir/224437/180 "2013-04-04T13:22:46Z")

</div>

this is interesting,

b.text\_field(:id,from spreadsheet).set(from spreadsheet)

But how do you know "from spreadsheet"part from spreadsheet? because id  
is the screen dependent,isn’t it so?

RAJ

[Previous page](https://www.ruby-forum.com/t/question-on-watir/224437.md?page=8)

[Next page](https://www.ruby-forum.com/t/question-on-watir/224437.md?page=10)
