Documente Academic
Documente Profesional
Documente Cultură
https://leanpub.com/watirways/read
1 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
2 of 22
4/28/2014 5:55 AM
Read Watirways | Leanpub <div class="city" id="Kitchener"> <div class="street" id="MainStreet"> <div class="house" data-name="SmithFamily" data-numb er="1"> <span class="resident">Ronald</span> <span class="resident">Alice</span> </div> <div class="house" data-name="WilsonFamily" data-num ber="2"> <span class="resident">Henry</span> <span class="resident">Mary</span> </div> </div> <div class="street" id="CedarStreet"> <div class="house" data-name="ChanFamily" data-numbe r="1"> <span class="resident">Blake</span> <span class="resident">Terra</span> </div> <div class="house" data-name="SmithFamily" data-numb er="2"> <span class="resident">George</span> <span class="resident">Coraline</span> </div> </div> </div>
https://leanpub.com/watirways/read
3 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
browser.div
4 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
browser.div
5 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
browser.ul
6 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
<li class="lastMove"> <div id="81ae2" class="folder"> <small onclick="someFunction1()"> </small> </div> </li>
7 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
8 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
9 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
<div> <span customattribute="custom1">Custom Attribute 1</ span> <span customattribute="custom2">Custom Attribute 2</ span> <span customattribute="custom3">Custom Attribute 3</ span> </div>
10 of 22
4/28/2014 5:55 AM
Read Watirways | Leanpub browser.div(:text => 'This is the text of the element.')
https://leanpub.com/watirways/read
11 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
12 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
<span>Project Managers:</span> <ul id="project_managers"> <li>Alicia Mcbride</li> <li>Jake Woods</li> </ul> <span>Developers:</span> <ul id="developers"> <li>Jack Greer</li> <li>Cora Williamson</li> <li>Albert Gross</li> </ul> <span>Testers:</span> <ul id="testers"> <li>Owen Francis</li> <li>Luis Leonard</li> </ul>
13 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
<ul> <li id="ctl00_EnabledComponentListItem"> <a id="ctl00_Component" data-componentcode="ItemA" h ref="#">Item A</a> <a href="#">X</a> </li> <li id="ctl01_EnabledComponentListItem"> <a id="ctl01_Component" data-componentcode="ItemB" h ref="X">Item B</a> <a href="#">X</a> </li> <li id="ctl02_EnabledComponentListItem"> <a id="ctl02_Component" data-componentcode="ItemC" h ref="#">Item C</a> <a href="#">X</a> </li> </ul>
browser.a(:data_componentcode, 'ItemC').parent
14 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
<table> <tbody> <tr> <th>Creature</th> <th>Colour</th> </tr> <tr> <td>Elf</td> <td>Blue</td> </tr> <tr> <td>Dragon</td> <td>Green</td> </tr> <tr> <td>Imp</td> <td>Black</td> </tr> </tbody> </table>
#Get the unique element unique_element = browser.table.td(:text => 'Dragon') #Get the parent element parent_element = unique_element.parent #Get the actual element parent_element.td(:index => 1).text #=> "Green"
15 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
parent_row = browser.table.trs.find do |tr| tr.td(:text => 'Dragon').present? end parent_row.td(:index => 1).text #=> "Green"
<html> <body> <h1>Heading 1</h1> <ul> <li>Item 1a</li> </ul> <h1>Heading 2</h1> <ul> <li>Item 2a</li> <li>Item 2b</li> </ul> </body> </html> 16 of 22 4/28/2014 5:55 AM
https://leanpub.com/watirways/read
h1 = browser.h1(:text => 'Heading 2') ul = h1.element(:xpath => './following-sibling::*') puts ul.lis.length #=> 2
h1 = browser.h1(:text => 'Heading 2') ul = h1.element(:xpath => './preceding-sibling::*[1]') puts ul.lis.length #=> 1
start_h1 = browser.h1(:text => 'Heading 2') end_h1 = start_h1.h1(:xpath => './preceding-sibling::h1[ 1]') puts end_h1.text #=> "Heading 1"
h1 = browser.h1(:text => 'Heading 2') ul = browser.ul(:ole_object => h1.document.nextSibling) puts ul.lis.length #=> 2
h1 = browser.h1(:text => 'Heading 2') ul = browser.ul(:ole_object => h1.document.previousSibli ng) puts ul.lis.length #=> 1
17 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
<div style="color:red;">Error</div>
18 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
<div class="error_message">Error</div>
<body> <div id="1" style="block:display;">This text is visibl e</div> <div id="2" style="block:none;">This text is not visib le</div> </body> 19 of 22 4/28/2014 5:55 AM
https://leanpub.com/watirways/read
20 of 22
4/28/2014 5:55 AM
Read Watirways | Leanpub Watir::Exception::UnknownObjectException: Unable to locate element, using {:tag_name=>["div"]} from ../lib/watir-classic/element.rb:66:in `assert_exi sts' from ../lib/watir-classic/element.rb:125:in `text' from (irb):5 from C:/Ruby193/bin/irb:12:in `<main>'
https://leanpub.com/watirways/read
browser.frame.div.text
browser.div.when_present.text
browser.div(:id, 'static_rand5').text
browser.div(:id, /static/).text
21 of 22
4/28/2014 5:55 AM
https://leanpub.com/watirways/read
browser.b tton.clic!
browser.lin!.clic!
22 of 22
4/28/2014 5:55 AM