robotframework / robotframework/robotframework
Add `Parse HTML` keyword to XML Library
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 11.9k
- Forks
- 2.6k
- Avg merge
- 1d 18h
- Merged PRs (30d)
- 10
Description
I would like to suggest adding a Parse HTML keyword to XML Library.
Why:
- I have a need to test the html output from an application that output's a html file to the local file system
- I found that when I tried to parse the html file with the
Parse XMLkeyword I get errors because html elements are not valid xml<meta>and<img>elements do not have closing elements and fail xml validation
- I do not want to install a web browser and browser based library and the necessary dependencies on my test runner just to test the html output, loading the html as an element tree and then using the XML Library keywords allows me to test what is needed.
Alternatives:
None really, I considered creating a HTML library that would basically be a copy of XML Library but it seems like a big duplication of effort, as it would be using the same lxml.etree module anyway.
Workaround:
Currently my workaround is to load the html as an element tree using the html parser, then pass the etree object to the XML library keywords, example below:
VAR ${sectionid}= "my_section_id"
VAR ${htmlfile}= "/path/to/file/myfile.html"
${html}= Evaluate lxml.etree.parse(r'${htmlfile}', lxml.etree.HTMLParser()) modules=lxml.etree
${table}= Get Element ${html} //div[@id='${sectionid}']//table
${value}= Get Elements Texts ${table} tr/td[1]
Would you like me to work on a PR for this?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the XML Library implementation and the existing Parse XML keyword, then review the reported lxml.etree.HTMLParser workaround. Done means a Parse HTML keyword can load HTML that is not XML and allow the existing XML Library element and text keywords to operate on it without XML validation errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- testing
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100