DOM.A content

18 views
Skip to first unread message

Dan Bogart

unread,
Jun 5, 2013, 4:18:38 PM6/5/13
to webel...@googlegroups.com
I seem to be missing something on how to specify the content for an anchor element. Do I have to add a child element (such as a span) to accommodate the display text or can I specify it directly via the A class?

Thanks!

timothy crosley

unread,
Jun 5, 2013, 4:37:27 PM6/5/13
to webel...@googlegroups.com
Hi Dan,

WebElements has a special TextNode element that is meant to be used to represent any text contained within elements. And as all DOM elements have no special handling but are direct translation of their HTML5 specifications you have to manually add the TextNode if you choose to use the DOM.A class directly:

from WebElements import DOM, Base


link
= DOM.A(href="http://www.google.com/")
link
+= Base.TextNode(text="Go to Google!")



print link

 Which outputs:

<a href="http://www.google.com/">
 Go to Google!
</a>



That said, what you probably want to do is use Buttons.Link (Which is a child class of DOM.A) instead. This will automatically add the text node if text is specified:

from WebElements.Buttons import Link

print Link(href="http://www.google.com/", text="Go to Google!")

Which will result in the exact same HTML output.

I hope this make sense. You're welcome, thank you for asking the question :)

Timothy
Reply all
Reply to author
Forward
0 new messages