ruby watir organize
Watir-based treatment, inheritance in ")
5.3. To amend the framework of the bottom
Such an approach, in view of the pop-up box 3.
For one, upload download document
1, modify the underlying code input_elements.rb documents,
FileField category, the methods set.
Support for English, there is a replacement amended to read:
system ( "rubyw-e \" require 'win32ole'; @ autoit = WIN32OLE.new ( 'AutoItX3.Control'); 'Choose file','', 15; sleep 1; if waitresult == 1 \ "-e \" @ autoit.ControlSetText 'Choose file','', 'Edit1', '# (setPath)'; @ autoit. ControlSend 'Choose file','', 'Button2', '(ENTER)'; \ "-e \" end \ "")
2, the definition of Ways
def save_file (filepath)
ai = WIN32OLE.new ( "AutoItX3.Control")
ai.WinWait ( "File Download", "", 5)
ai.ControlFocus ( "File Download", "", "save (& S)")
sleep 1
ai.ControlClick ( "File Download", "", "save (& S)", "left")
ai.WinWait ( "Save As", "", 5)
sleep 1
ai.ControlSend ( "Save As", "", "Edit1", filepath)
ai.ControlClick ( "Save As", "", "save (& S)", "left")
ai.WinWait ( "download completed", "", 5)
ai.ControlClick ( "download completed", "", "turn off")
end
3, procedure body code:
ie.file_field (: name, "xlsfile"). set ( "c: \ \ samenameobject.html")
# Upload the file you specified
Or
ie.span (: text, "Export Excel Table"). click_no_wait
save_file ( "C: \ \ abc.xls")
# Download to your specified path
3 for the pop-up box, the query and user intervention required to operate:
For two, in the Medium Category for crm and customer selection of the pop-up box, with the first implementation in different ways is that
Medium WinActivate used autoit and ControlClick method
require 'rubygems'
require 'watir' # the watir controller
require 'watir / WindowHelper'
require 'win32ole'
def check_for_popups
autoit = WIN32OLE.new ( 'AutoItX3.Control')
loop do
ret = autoit.Winwait ( "select - page dialog", "", 1)
puts ret
if (ret == 1) then
autoit.WinActivate ( "[CLASS: Internet Explorer_TridentDlgFrame]", "")
autoit.Send ( "(TAB)")
autoit.Send ( "(TAB)")
# autoit.Send ( "Huzhou")
# autoit.Send ( "(ASC 2709)")
# autoit.SendUnicode ( "a")
# autoit.ClipPut ( "hang")
# autoit.ClipGet
# autoit.ToolTip "This is a tooltip Hangzhou", 0, 0
# autoit.Sleep 2000
autoit.Send ( "(TAB)")
autoit.Send ( "(TAB)")
autoit.Send ( "(Enter)")
autoit.WinActivate ( "[CLASS: Internet Explorer_TridentDlgFrame]", "")
autoit.ControlClick ( "select - page dialog", "", "[CLASS: Internet Explorer_TridentLstBox; INSTANCE: 2]", 2)
autoit.Send ( "(TAB)")
autoit.Send ( "(Enter)")
autoit.Send ( "(TAB)")
autoit.Send ( "(TAB)")
autoit.Send ( "(TAB)")
autoit.Send ( "(TAB)")
autoit.Send ( "(Enter)")
end
sleep (3)
end
end
ie = Watir:: IE.new
ie.goto ( " ")
# ie.goto ( " ")
# ie.element_by_xpath ( "/ / span [contains (text (), 'Main Road Nijmegen')]"). click
ie.text_field (: name, "id"). set ( "mhl1805")
ie.text_field (: name, "password"). set ( "zxcvbnm")
ie.button (: name, "signin"). click
ie.frame (: name, "left"). link (: url, "
ie.frame (: name, "left"). link (: text, "for new customers to sign in"). click
# Start popup handler
ie.frame (: name, "right"). frame (: name, "rtop"). button (: value, "Customer Choice"). click_no_wait
sleep (20)
$ popup = Thread.new (check_for_popups)
at_exit (Thread.kill ($ popup))
For the third popup window, if required with user interaction, and the need to input Chinese characters, if treated with autoit sendkey Supported English (but official documentation says that it supports Chinese input, on-line there is a lot of same questions and I met), there is no to find an effective program, pending further follow-up.
In addition to the above pop-up box outside the required special treatment, watir also there is some expansion of tag, or third-party control of the required special treatment,
Like:
5.4. Web HTML editor html editor of the English Station provides: operator ID, or name more convenient to operate directly
require 'rubygems'
require 'watir' # the watir controller
require 'watir / WindowHelper'
require 'win32ole'
ie = Watir:: IE.new
ie = Watir:: IE.attach (: title, / Ali aides /)
ie.text_field (: name, "_fmo.a._0.s"). set ( "mhl1805")
ie.document.getElementByid ( "_editor"). contentWindow.focus ()
ie.send_keys ( "abcsadfasfd")
But also encountered some web pages, does not provide any ID, can only be used to send tab Ways autoIT implementation
require 'rubygems'
require 'watir' # the watir controller
require 'watir / WindowHelper'
require 'win32ole'
ie = Watir:: IE.new
# ie = Watir:: IE.attach (: title, / Alibaba /)
ie.goto ( 'http://us.my.alibaba.com/product/buyoffer/post_buying_lead.htm')
ie.text_field (: name, "_fmp.bu._0.su"). set ( "mhl1805")
ie.text_field (: name, "_fmp.bu._0.su"). set ( "China")
ie.checkbox (: id, "detailDesc"). set
ie.checkbox (: id, "detailDesc"). focus ()
ie.send_keys ( "\ t" * 9)
ie.send_keys ( 'Hello Worldabcdef')
5.5. Object identification other methods commonly used built-TAG quote
Such as: IE.div, ie.span, ie.cell, ie.table way to achieve click operation, value operation.
In addition the provision of QTP descriptive programming similar, with the type of object statistics:
ie.buttons.each (| b | puts b.to_s)
puts ie.checkboxes.length
puts ie.links.length
and so on puts ie.buttons.length
For commonly used InnerText property, has been at watir package to methods can be directly quoted. Such as:
ruby at the bottom of the object to identify, package the InnerText
Implementation, called Ways text can be:
Such as: puts ie.div (: id, "intelligentWord"). Link (: id, index.to_s). Text
Finally: return text and source code, use the following methods:
puts ie.text ()
puts ie.html ()
5.6. Identification of the target regular expression support
Of course, ruby to provide powerful support for regular expressions, such as: property identification is then
ie = Watir:: IE.attach (: title, / Alibaba /)
Ruby's regular expressions with "/ /" as the basic framework for the content of expression is located in "/" between. Expressions return a RegExp object.
Expression of the general rules:
/ a / matches the characters a.
/ \? / Matching special characters?. Special characters, including ^, $,?,., /, \, [,], (,), (,), +, *.
. Matches any character, such as / a. / matches ab and ac.
/ [ab] c / matching ac and bc, [] between the scope of representation. For example: / [az] /, / [a-zA-Z0-9] /.
/ [^ a-zA-Z0-9] / matches are not within the scope of the string.
/ [\ d] / on behalf of any figure, / [\ w] / on behalf of any letters, numbers or _, / [\ s] / on behalf of whitespace characters, including spaces, TAB, and newline.
/ [\ D ]/,/[ \ W ]/,/[ \ S] / are the above-mentioned negative situation.
The other is about the usage, please refer to "watir Technical Highlights"
5.7. Finally Raiders
In short, for object recognition and operation, it is necessary to help the above-mentioned document, and flexibility in the use of autoit, xpath object and abnormal operation. Watir does not support the control of windows, I was thinking about the first method is the adoption of third-party autoit technology, to simulate the keyboard or mouse operation.
For the operation of web objects, watir does not support the special tag, except the expansion of its underlying code, the only deep look at the xpath.
Finally,搞不定, only to watir group in a consultative expert, huh, huh.
There is no other better way to encounter. . .
Some errors
If the error AutoITX3, it helps to make automation happen
Then run at windows
regsvr32 "C: \ ruby \ lib \ ruby \ gems \ 1.8 \ gems \ watir-1.6.2 \ lib \ watir \ AutoItX3.dll"
Unknown OLE server: `AutoItX3.Control '(WI2OLERuntimeError)
that might mean you have not resisted the AutoItX3.dll in your computer,
in current Watir version, AutoItX3.dll has been included in the watir folder,
so Run the command in "Run":
regsvr32 "C: \ ruby \ lib \ ruby \ gems \ 1.8 \ gems \ watir-1.6.2 \ lib \ watir \ AutoItX3.dll"
then you will not get the errors:)
learn AutoItX3, please go to http://www.autoitscript.com/autoit3/index.shtml
I just want to use it to handle the popup windows when writing Watir scripts
Tags: inheritance (RSS), ruby (RSS), current user (RSS), two kinds (RSS), quot quot quot quot (RSS), internet explorer (RSS), implementation approach (RSS), application solutions (RSS), pop up window (RSS), document object (RSS), open web standards (RSS), input operation (RSS), class button (RSS), object recognition (RSS), link button (RSS), web document (RSS), keystroke (RSS), dialog box (RSS), autoit (RSS), confirmation (RSS)





















