[Celerity-users] click_and_attach Celerity::Exception::UnknownObjectException: no page loaded

jason franklin-stokes jasoninclass at googlemail.com
Sat Dec 12 18:59:32 EST 2009


Dear Jari,

fyi, i can get no further with click_and_attach - the way it behaves makes no sense to me.

I have added a new method to browser which does the same thing as click and attach but without generating a new instance of browser - which feels wrong anyway:

def click_and_open_in_new_window
    assert_exists_and_enabled
    rescue_status_code_exception { browser.page = @object.openLinkInNewWindow }
end

also the celerity browser url method is using a depreciated htmlunit method so i changed that too: 

 def url
   assert_exists
   @page.getWebResponse.getRequestSettings.getUrl.toString
 end

this now returns the correct url rendered by element clicked returned from the server. 

This way i don't have to acquire a new instance of browser and close all windows of the browser instance after calling click_and_attach - which does not seem to work correctly anyway - at least in my case where i click several links in sequence using click_and_attach. 

The following code now works and no htmlunit javascript threads are left hanging around - code is shorter and less stuff happening that can go wrong (new browser instances, cookie handlers being copied, and listeners being lost , i.e. having to be setup again etc etc. 

browser=Celerity::Browser.new
browser.goto "http://www.swisspost.com"
browser.wait

element = browser.elements_by_xpath("/html/body/div[2]/div/div[4]/div[1]/ul[2]/li[2]/a").first
element.click_and_open_in_new_window # instead of click_and_attach
browser.wait

puts browser.url  # correct url is returned and and page is loaded

element = browser_0.elements_by_xpath("/html/body/div[2]/div/div[4]/div[1]/ul[1]/li[1]/a").first
element.click_and_open_in_new_window # instead of click_and_attach
browser.wait

puts browser.url # correct url is returned and page is loaded - would normally break here if click_and_attach was being used

browser.close # only needs to be done here and not for use of each click_and_attach

Jason.



On Dec 12, 2009, at 5:43 PM, Jari Bakken wrote:

> On Sat, Dec 12, 2009 at 5:17 PM, jason franklin-stokes
> <jasoninclass at googlemail.com> wrote:
>> browser = new_browser
>> 
>> browser.url     # Celerity::Exception::UnknownObjectException: no page loaded
>> 
>> 
> 
> You need to navigate somewhere (i.e. Browser#goto) before you call Browser#url.
> _______________________________________________
> Celerity-users mailing list
> Celerity-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/celerity-users



More information about the Celerity-users mailing list