New issue 208 by manga...@gmail.com: Add keywords for working with inner
HTML of an element
http://code.google.com/p/robotframework-seleniumlibrary/issues/detail?id=208
I may submit a patch with the requested enhancement later on, but in either
case, entering issue for tracking purposes and as FYI.
A common feature for websites and web apps these days is working with
innerHtml of an element via the DOM. Perhaps is a seldom used feature with
respect to Selenium test automation, but can be useful when there is a need
for it, particularly in cases of AJAX dynamic generation of DOM elements
and their HTML, where getting HTML page source may or may not have the
matching HTML subset.
Even if it did match, why grab all the bloated HTML when sometimes you just
need a subset.
Suggested keywords based on current library:
* keyword, arguments
* Get Inner Html, locator
* Log Inner Html, locator
Keyword can be implement with this type of code snippet that I've used in
another Selenium project.
return selenium.getEval("this.browserbot.findElement(\"" + locator
+ "\").innerHTML");
Comment #1 on issue 208 by janne.t....@gmail.com: Add keywords for
working with inner HTML of an element
http://code.google.com/p/robotframework-seleniumlibrary/issues/detail?id=208
This sounds reasonable (and trivial to implement)
1) Is innerHTML just an element attribute? If yes, isn't Get Element
Attribute enough instead of Get Inner HTML?
2) I don't think separate Log Inner HTML keyword is need anyway. We don't
have it for other elements or attributes either and you can very easily use
BuiltIn keyword Log for this purpose. The Log Source keyword is an
exception for the most common case.
I will confirm with a test shortly, but innerHtml is a special DOM
attribute of all elements, which might not be able to extract with the
default Selenium's getAttribute() method. Hence my suggested code snippet.
Getting attributes is generally for items that are exposed in the element
itself in source code like:
<input id=val value="some value" style="" attributeName="someValue"/>
Where id, value, style, and attributeName are all valid attributes.
innerHtml is never defined within an element tag. It's a special attribute
that's only manipulated and accessed by javascript and CSS. I believe as a
Selenium user, you also have to use javascript like browserbot to access
such DOM attributes or properties.
Verified trying to get the special DOM attribute with Get Element Attribute
fails.
FAIL ERROR: Could not find element attribute: id=promo-message@innerHTML
The following SeleniumLibrary command however works:
| ${html}= | Call Selenium Api | getEval |
this.browserbot.findElement('id=promo-message').innerHTML |
So we just need a keyword that will do that w/o user having to directly use
the Selenium API.
although the return value seemed to be a tuple for getEval, as returned by
Call Selenium Api:
${html} = OK,
<p><script>utmx_section("SMBHomePageTest")</script><a
href="/promo/tiny-prints-coupon-codes-promotions.htm"><strong>Save Big on
Holiday Cards! Enjoy Up to 20% Off Your Order</strong> | Code: OCTHO...