Watir学习笔记之一 浏览器的简单使用

来源:互联网 发布:linux ubuntu iso下载 编辑:程序博客网 时间:2024/05/21 09:46

Load the Watir libraryrequire 'watir' Open a browser (default: Internet Explorer)browser = Watir::Browser.new Open Browser at the specified URL browser = Watir::Browser.start("http://google.com")

Go to a specified URL browser.goto("http://amazon.com")

Close the browserbrowser.close

Browser options (IE only)Speed up execution(or use the "-b" command line switch)browser.speed = :fast Maximize browser windowbrowser.maximize

Pop browser window to frontbrowser.bring_to_front Access an ElementText box or text area

t = browser.text_field(:name, "username")

Buttonb = browser.button(:value, "Click Here")

Drop down list

d = browser.select_list(:name, "month") Check box

c = browser.checkbox(:name, "enabled")

Radio buttonr = browser.radio(:name, "payment type")

Formf = browser.form(:name, "address")f = browser.form(:action, "submit")

Linkl = browser.link(:url, "http://google.com")l = browser.link(:href, "http://google.com")

Table cell in a table (2nd row, 1st column)

td = browser.table(:name, 'recent_records')[2][1] Manipulate the ElementClick a button or linkb.clickl.click Enter text in a text boxt.set("mickey mouse") Enter multiple lines in a multi-line text boxt.set("line 1/nline2") Set radio button or check boxc.setr.set Clear an elementt.clearc.clearr.clear Select an option in a drop down listd.select "cash"d.set "cash" Clear a drop down listd.clearSelection Submit a formf.submit Flash any element (useful from the watir-console)e.flash Check the ContentsReturn the html of the page or any elementbrowser.htmle.html Return the text of the page or any elementbrowser.texte.text Return the title of the documentbrowser.title Get text from status bar.browser.status=> "Done" Return true if the specified text appears on the pagebrowser.text.include? 'llama' Return the contents of a table as an arraybrowser.table(:id, 'recent_records').to_a

原创粉丝点击