Okay, I just the answer that works in getting the class name.
.attribute_value('*class*')
Here is my code:
section_headers.each do|sec_hdr|
puts hdr = sec_hdr.attribute_value('class')
if hdr == 'item digest-options'
puts hdr_1 = $browser.li(:class,'item digest-options').h2.text
end
end
item subscriptions-description
item digest-options
* header = Digest Options
item community-features
item member-discussions
ree-1.8.7-2010.02 :050 > section_headers.each do|sec_hdr|
ree-1.8.7-2010.02 :051 > puts hdr = sec_hdr.attribute_value('class')
ree-1.8.7-2010.02 :052?> end
item subscriptions-description
item digest-options
item community-features
item member-discussions
On Mon, Nov 7, 2011 at 9:07 AM, Joe Fleck <[email protected]> wrote:
> So, I won't be able to retrieve those headers because the first one has a
> <p> in it.
>
> Why is it when I try to get the li class name it returns?
>
> ree-1.8.7-2010.02 :041 > section_headers.each do|sec_hdr|
> ree-1.8.7-2010.02 :042 > puts hdr = sec_hdr.class
> ree-1.8.7-2010.02 :043?> end
> Watir::LI
> Watir::LI
> Watir::LI
> Watir::LI
>
> On Mon, Nov 7, 2011 at 8:40 AM, Michael <[email protected]> wrote:
>
>> That appears to be because your first LI doesn't have a H2 inside of it.
>> When you put one LI after another, the browser will automatically close the
>> first before the second opens.
>>
>> <ul class="items">
>> <li class="item subscriptions-description">
>> <li class="item digest-options">
>> <h2>Digest Options</h2>
>>
>>
>> Fix your HTML syntax and you should be good to go.
>>
>> Michael
>>
>> On 2011-Nov-07, at 6:08 AM, Joe Fleck wrote:
>>
>> No worries,
>>
>> here is what I got when I ran the code:
>>
>> ree-1.8.7-2010.02 :024 > section_headers = $browser.div(:class,"mod
>> simple your-subscriptions").div(:class,"bd").ul(:class,"items").lis
>> => #<Watir::LICollection:0x1044bf000 @parent=#<Watir::UList:0x1044bf0f0
>> located=false selector={:class=>"items", :tag_name=>"ul"}>,
>> @selector={:tag_name=>"li"}>
>> ree-1.8.7-2010.02 :025 > section_headers.each do|sec_hdr|
>> ree-1.8.7-2010.02 :026 > puts hdr = sec_hdr.h2.text
>> ree-1.8.7-2010.02 :027?> end
>> Watir::Exception::UnknownObjectException: unable to locate element, using
>> {:tag_name=>"h2"}
>> from
>> /Users/josephfleck/.rvm/gems/ree-1.8.7-2010.02/gems/watir-webdriver-0.3.4/lib/watir-webdriver/elements/element.rb:248:in
>> `assert_exists'
>> from
>> /Users/josephfleck/.rvm/gems/ree-1.8.7-2010.02/gems/watir-webdriver-0.3.4/lib/watir-webdriver/elements/element.rb:55:in
>> `text'
>> from (irb):26
>> from
>> /Users/josephfleck/.rvm/gems/ree-1.8.7-2010.02/gems/watir-webdriver-0.3.4/lib/watir-webdriver/element_collection.rb:21:in
>> `each'
>> from
>> /Users/josephfleck/.rvm/gems/ree-1.8.7-2010.02/gems/watir-webdriver-0.3.4/lib/watir-webdriver/element_collection.rb:21:in
>> `each'
>> from (irb):25
>> from
>> /Users/josephfleck/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems.rb:406
>>
>> If I do it this way:
>>
>> ree-1.8.7-2010.02 :034 > section_headers.each do|sec_hdr|
>> ree-1.8.7-2010.02 :035 > puts hdr = sec_hdr.text
>> ree-1.8.7-2010.02 :036?> end
>>
>> I get this output which at a level to high
>>
>> Association CDK Sandbox provides you with all updates from the community
>> that you subscribe to in a single email, delivered weekly or daily. You can
>> customize the content of your digest and how often you want to receive it.
>> To stop receiving the digest, just set the frequency of updates to never.
>> * Digest Options
>> Frequency of digest:
>> Weekly
>> Daily
>> Never
>> Format of digest:
>> HTML Format (images)
>> Text Only
>> * Community Features
>> Guided Discussions
>> * Member Discussion Topics
>> Select the topics you're interested in to receive activity updates in
>> those areas.
>> Engineering
>> UX
>> QA
>>
>> I have starred those headers I need.
>>
>>
>>
>> On Sun, Nov 6, 2011 at 9:45 PM, Michael <[email protected]> wrote:
>>
>>> A second looks at your code made me think you should be using ul
>>> (singular because you only have one), and append lis on the end to get all
>>> the li's contained within the ul.
>>>
>>> My Code:section_headers =
>>> $browser.div(:class,"bd").ul(:class,"items").lis
>>>
>>>
>>> Sorry about the first response, please disregard it.
>>>
>>> Michael
>>>
>>> On 2011-Nov-06, at 7:40 PM, Michael wrote:
>>>
>>> You probably intended to use uls which will return a list of ul's
>>> instead of ul which only returns the first matching ul.
>>>
>>> Try:
>>>
>>> My Code:section_headers = $browser.div(:class,"bd").uls(:class,"items")
>>>
>>>
>>> Michael
>>>
>>> On 2011-Nov-06, at 7:09 PM, Joe Fleck wrote:
>>>
>>> Hi Chuck,
>>>
>>> I am still having a bit of trouble with getting a group of h2 from a
>>> page.
>>>
>>> My Code:section_headers = $browser.div(:class,"bd").ul(:class,"items")
>>> section_headers.each do|sec_hdr|
>>> puts hdr = sec_hdr.h2.text
>>> end
>>>
>>> I get the following error message.
>>> NoMethodError: undefined method `each' for #<Watir::UList:0x10aa117f0>
>>> from
>>> /Users/josephfleck/.rvm/gems/ree-1.8.7-2010.02/gems/watir-webdriver-0.3.4/lib/watir-webdriver/elements/element.rb:295:in
>>> `method_missing'
>>> from (irb):10
>>> from
>>> /Users/josephfleck/.rvm/rubies/ree-1.8.7-2010.02/lib/ruby/site_ruby/1.8/rubygems/deprecate.rb:58
>>>
>>>
>>> The HTML Code:
>>> <div class="mod simple your-subscriptions">
>>> <div class="inner">
>>> <div class="hd">
>>> <div class="bd">
>>> <ul class="items">
>>> <li class="item subscriptions-description">
>>> <li class="item digest-options">
>>> <h2>Digest Options</h2>
>>> <div class="line form">
>>> <div class="unit size2of5">
>>> <div class="line lastUnit size3of5">
>>> <label class="wide-label" for="digest_setting_email_format">Format of
>>> digest:</label>
>>> <select id="digest_setting_email_format" name="
>>> digest_setting[email_format]" data-method="put" data-href="
>>> /digest_settings/488" data-command="change">
>>> </div>
>>> </div>
>>> </li>
>>> <li class="item community-features">
>>> <h2>Community Features</h2>
>>> <div class="line form">
>>> <input id="109" class="unit content-feed-subscribe checkbox mrm" type="
>>> checkbox" value="content-feed-109" name="content_feed_Guided Discussions
>>> " data-subscription-url="/content_feeds/109/subscribe?channel_id=57"
>>> data-content-feed-id="109">
>>> <label class="unit label-for-checkbox" for="109">Guided Discussions</
>>> label>
>>> </div>
>>> </li>
>>> <li class="item member-discussions">
>>> <h2>Member Discussion Topics</h2>
>>> <p>Select the topics you're interested in to receive activity updates
>>> in those areas.</p>
>>> <div class="line form">
>>> <div class="unit size1of2">
>>> <div class="line checkbox-row">
>>> <input id="107" class="unit content-feed-subscribe checkbox mrm" type="
>>> checkbox" value="content-feed-" name="content_feed_Engineering"
>>> data-subscription-url="/content_feeds/107/subscribe?channel_id=57"
>>> data-content-feed-id="107">
>>> <label class="unit label-for-checkbox" for="107">Engineering</label>
>>> </div>
>>> <div class="line checkbox-row">
>>> <input id="108" class="unit content-feed-subscribe checkbox mrm" type="
>>> checkbox" value="content-feed-" name="content_feed_UX"
>>> data-subscription-url="/content_feeds/108/subscribe?channel_id=57"
>>> data-content-feed-id="108">
>>> <label class="unit label-for-checkbox" for="108">UX</label>
>>> </div>
>>> </div>
>>> <div class="unit size1of2 lastUnit">
>>> <div class="line checkbox-row">
>>> <input id="110" class="unit content-feed-subscribe checkbox mrm" type="
>>> checkbox" value="content-feed-" name="content_feed_QA"
>>> data-subscription-url="/content_feeds/110/subscribe?channel_id=57"
>>> data-content-feed-id="110">
>>> <label class="unit label-for-checkbox" for="110">QA</label>
>>> </div>
>>> </div>
>>> </div>
>>> </li>
>>> </ul>
>>>
>>> I just want the h2 header.
>>>
>>> On Fri, Oct 21, 2011 at 5:07 PM, Chuck van der Linden
>>> <[email protected]>wrote:
>>>
>>>>
>>>>
>>>> On Oct 21, 10:41 am, Joe Fl <[email protected]> wrote:
>>>> > Hi,
>>>> >
>>>> > I need to retrieve multiple discusion titles from a page. I just want
>>>> > the titles only and there can be 5 to 13 on a page with other links
>>>> > listed under them. I have tried the following and it will only return
>>>> > the first discussion title or all links:
>>>> >
>>>> > subject_lines =
>>>> >
>>>> $browser.div(:class,'one_col_select').div(:id,'naph').div(:id,'discussion-
>>>> > board').span(:class,'discussion-title').links
>>>> >
>>>> > subject_lines.each do|link|
>>>> > puts title_name = link.text
>>>> > end
>>>> >
>>>>
>>>> Your problem is that you are telling it to get all the links from
>>>> within a single span. I think what you need to do is get all the
>>>> spans which contain those links, and then pull the link text, OR if
>>>> the only links on the page are those of the class theme are the ones
>>>> you want, then just go for the links directly
>>>>
>>>> If you can go after the links, then
>>>>
>>>> subject_links = $browser.links(:class, 'theme')
>>>>
>>>> subject_links.each do|link|
>>>> puts link.text
>>>> end
>>>>
>>>> If the links are not unique enough on their own, then unless there are
>>>> other spans on the page with the discussion_title class that you don't
>>>> want, you need to do something more along these lines
>>>>
>>>> subjects = $browser.spans(:class,'discussion-title')
>>>>
>>>> subjects.each do|subject|
>>>> puts subject.link.text #presumes we want first link inside the
>>>> span
>>>> end
>>>>
>>>> --
>>>> Before posting, please read http://watir.com/support. In short: search
>>>> before you ask, be nice.
>>>>
>>>> [email protected]
>>>> http://groups.google.com/group/watir-general
>>>> [email protected]<http://groups.google.com/group/[email protected]>
>>>>
>>>
>>>
>>> --
>>> Before posting, please read http://watir.com/support. In short: search
>>> before you ask, be nice.
>>>
>>> [email protected]
>>> http://groups.google.com/group/watir-general
>>> [email protected]
>>>
>>>
>>>
>>> --
>>> Before posting, please read http://watir.com/support. In short: search
>>> before you ask, be nice.
>>>
>>> [email protected]
>>> http://groups.google.com/group/watir-general
>>> [email protected]
>>>
>>>
>>>
>>> --
>>> Before posting, please read http://watir.com/support. In short: search
>>> before you ask, be nice.
>>>
>>> [email protected]
>>> http://groups.google.com/group/watir-general
>>> [email protected]
>>>
>>
>>
>> --
>> Before posting, please read http://watir.com/support. In short: search
>> before you ask, be nice.
>>
>> [email protected]
>> http://groups.google.com/group/watir-general
>> [email protected]
>>
>>
>> --
>> Before posting, please read http://watir.com/support. In short: search
>> before you ask, be nice.
>>
>> [email protected]
>> http://groups.google.com/group/watir-general
>> [email protected]
>>
>
>
--
Before posting, please read http://watir.com/support. In short: search before
you ask, be nice.
[email protected]
http://groups.google.com/group/watir-general
[email protected]