MuraliKola / robotframework-seleniumlibrary

Automatically exported from code.google.com/p/robotframework-seleniumlibrary
Apache License 2.0
1 stars 0 forks source link

New `Get Inner HTML` keyword #208

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
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");

Original issue reported on code.google.com by manga...@gmail.com on 17 Oct 2011 at 2:32

GoogleCodeExporter commented 8 years ago
This sounds reasonable (and trivial to implement)

Original comment by janne.t....@gmail.com on 17 Oct 2011 at 5:22

GoogleCodeExporter commented 8 years ago
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.

Original comment by pekka.klarck on 19 Oct 2011 at 10:40

GoogleCodeExporter commented 8 years ago
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.

Original comment by manga...@gmail.com on 19 Oct 2011 at 4:58

GoogleCodeExporter commented 8 years ago
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...

Original comment by manga...@gmail.com on 24 Oct 2011 at 4:15

GoogleCodeExporter commented 8 years ago

Original comment by pekka.klarck on 4 May 2012 at 10:06

GoogleCodeExporter commented 8 years ago
This issue was updated by revision 7b3c0f063258.

Original comment by robotframework@gmail.com on 4 May 2012 at 11:59

GoogleCodeExporter commented 8 years ago
We decided to implement only `Get Inner HTML`. You can easily use `Log` keyword 
to log the value if needed.

Original comment by robotframework@gmail.com on 4 May 2012 at 12:01