bernerdschaefer / akephalos

Headless HTMLUnit powered browser for Capybara
bernerdschaefer.github.com/akephalos
MIT License
338 stars 50 forks source link

dom tree leaves end up on the wrong branches #76

Open patrickhno opened 13 years ago

patrickhno commented 13 years ago

I had to add this to our massive project to make it work with the Akephalos driver. I guess this most likely will need to be passed on to some of the gems deeper down. I would guess htmlunit passes pure html to nokogiri so the htmlunit side of things should be fine I guess. What really bugs me is that this works fine with the selenium driver.

I think I can provide the raw html for a page that needs this workaround upon request.

This function seem to suffer a lot on pages with massive tables.

# Workaraound for a bug in the Akephalos driver
# Akephalos some times makes:
#   <tr>
#     <td><..><..><..></td>
#   </tr>
# into:
#   <tr>
#     <td><..></td>
#     <..>
#     <..>
#   </tr>
def self.akephalos_bug_workaround row
  ret = row.dup
  if row.name == 'tr'
    if row.children.size > 0 && row.children[0].respond_to?(:name) && row.children[0].name == 'td'
      ret.children = Nokogiri::XML::NodeSet.new(row.document)
      row.children.each do |td|
        if td.name == 'td'
          ret << td.dup
        else
          ret.children.last << td.dup
        end
      end
    end
  end
  ret
end
Nerian commented 12 years ago

Hi Patrick,

Does this happen in https://github.com/Nerian/akephalos2 ?

File a bug issue there if that is the case. A failing test sample would be extremely nice :)

Thanks