[Celerity-users] click_and_attach and popup ads

doridori Jo dorikick at gmail.com
Mon May 3 08:24:36 EDT 2010


1) how to set the HtmlPage returned by HtmlUnit into Celerity's browser page
?

set_actual_page window.getWebWindow.getParentWindow #<-- this is
HtmlPage....need to convert it to <#Celerity::Browser> object.....dont know
how

 def set_actual_page(page)
   # Add to collection on top
   @page << @browser.page   #<-- did u mean fix @pages to @page ?

   # Set actual page
   @browser.page = page
 end

okay well gonna sleep for now....been awake for 30 hours straight.

2010/5/3 doridori Jo <dorikick at gmail.com>

> that code complains about window.page....is that waht Tomasz meant ???
>
>
> 2010/5/3 doridori Jo <dorikick at gmail.com>
>
>> okay still not working....
>>
>> how do i set the page into celerity's browser.page ?
>>
>> set the @page variable ? where ?
>>
>> btw, i am now using this code now (i think i should learn java now):
>>
>>
>>             browser.add_listener(:web_window_event) { |window|
>>                 if
>> window.getWebWindow.is_a?(Java::ComGargoylesoftwareHtmlunit::TopLevelWindow)
>> &&
>>                     window.getEventType ==
>> Java::ComGargoylesoftwareHtmlunit::WebWindowEvent::CHANGE
>>
>>                         @old_top_window =
>> window.getWebWindow.getParentWindow
>>                         set_actual_page window.page
>>                 end
>>             }
>>
>> 2010/5/3 doridori Jo <dorikick at gmail.com>
>>
>> aye you are right jason. but i dont know Java ! :(
>>>
>>>
>>> On Mon, May 3, 2010 at 4:02 AM, jason franklin-stokes <
>>> jasoninclass at googlemail.com> wrote:
>>>
>>>> you need to set the @page variable
>>>>
>>>> - in general it looks like you want to scrape pages from different
>>>> websites - if you are celerity is not the right tool.
>>>> you should consider getting rid of it and using HtmlUnit directly.
>>>>
>>>> best Jason.
>>>>
>>>>
>>>> On May 3, 2010, at 11:36 AM, doridori Jo wrote:
>>>>
>>>> okay, so i have the page i want....not clear exactly what
>>>> web_window_event listener is doing...
>>>>
>>>> how to set it to browser.page ?
>>>>
>>>> i ended up with Java::ComGargoylesoftwareHtmlunitHtml::HtmlPage but how
>>>> can i set this into browser.page ?
>>>>             browser = Celerity::Browser.new()
>>>>             browser.add_listener(:web_window_event) { |window|
>>>>             if window.getNewPage == nil #this might be a popup window
>>>>             else
>>>>                 browser.page = window.getNewPage #Got the page i need
>>>> here....
>>>>                 puts window
>>>>             end
>>>>             }
>>>>             puts browser
>>>>             linkz = browser.element_by_xpath(someXpath)
>>>>             newbrowser = linkz.click_and_attach
>>>>
>>>> newbrowser should now contain the filtered page....but it doesn't
>>>>
>>>>
>>>> On Fri, Apr 30, 2010 at 12:58 PM, doridori Jo <dorikick at gmail.com>wrote:
>>>>
>>>>> Jari, i've submitted a new issue ticket on github.
>>>>>
>>>>> Tomasz, how will i use new_browser ? do i just declare it in the very
>>>>> beginning, and just continue using browser.link.click_and_attach ? kinda
>>>>> confused.
>>>>>
>>>>> For now, i think best thing is if i just don't use click_and_attach,
>>>>> maybe just use click....but click_and_attach is very useful !
>>>>>
>>>>>
>>>>>
>>>>> 2010/4/30 Tomasz Kalkosiński <tomasz2k at poczta.onet.pl>
>>>>>
>>>>> On Friday 30 of April 2010 11:32:35 Jari Bakken wrote:
>>>>>> > On Fri, Apr 30, 2010 at 11:14 AM, doridori Jo <dorikick at gmail.com>
>>>>>> wrote:
>>>>>> > >
>>>>>> > > So any way to deal with this ? i would very much prefer to use
>>>>>> > > click_and_attach, and be able to filter windows (like if URL
>>>>>> contains,
>>>>>> > > ad.doubleclick, ignore it)
>>>>>> > >
>>>>>> >
>>>>>> > That sounds like a sensible feature request, even though it's rarely
>>>>>> requested.
>>>>>> > Could you add an issue to the tracker on GitHub? Or even better,
>>>>>> write
>>>>>> > a patch :)
>>>>>>
>>>>>> I've dealt with it in my project. You have to look up for windows
>>>>>> collection. Something like snippet below, you have to experiment for
>>>>>> yourself.
>>>>>>
>>>>>>    def new_browser
>>>>>>
>>>>>>      @browser = Celerity::Browser.new
>>>>>>
>>>>>>      @browser.add_listener(:web_window_event) { |window|
>>>>>>
>>>>>>      if
>>>>>> window.getWebWindow.is_a?(Java::ComGargoylesoftwareHtmlunit::TopLevelWindow)
>>>>>> &&
>>>>>>          window.getEventType ==
>>>>>> Java::ComGargoylesoftwareHtmlunit::WebWindowEvent::OPEN
>>>>>>
>>>>>>      @old_top_window = window.getWebWindow.getParentWindow
>>>>>>      set_actual_page window.page
>>>>>>
>>>>>>      end
>>>>>>
>>>>>>      if window.getWebWindow.getName == "YourPreferredName" &&
>>>>>>          window.getEventType ==
>>>>>> Java::ComGargoylesoftwareHtmlunit::WebWindowEvent::CHANGE
>>>>>>
>>>>>>      ...
>>>>>>
>>>>>>
>>>>>>      end
>>>>>>
>>>>>>      }
>>>>>>
>>>>>>  def set_actual_page(page)
>>>>>>    # Add to collection on top
>>>>>>    @pages << @browser.page
>>>>>>
>>>>>>    # Set actual page
>>>>>>    @browser.page = page
>>>>>>  end
>>>>>>
>>>>>>
>>>>>> Greetings,
>>>>>> Tomasz Kalkosiński
>>>>>> _______________________________________________
>>>>>> Celerity-users mailing list
>>>>>> Celerity-users at rubyforge.org
>>>>>> http://rubyforge.org/mailman/listinfo/celerity-users
>>>>>>
>>>>>
>>>>>
>>>> _______________________________________________
>>>> Celerity-users mailing list
>>>> Celerity-users at rubyforge.org
>>>> http://rubyforge.org/mailman/listinfo/celerity-users
>>>>
>>>>
>>>>
>>>> _______________________________________________
>>>> Celerity-users mailing list
>>>> Celerity-users at rubyforge.org
>>>> http://rubyforge.org/mailman/listinfo/celerity-users
>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/celerity-users/attachments/20100503/51f8a1c7/attachment-0001.html>


More information about the Celerity-users mailing list