Get Element Attribute doesn't get 'type' values.

3,354 views
Skip to first unread message

Andrew Kolesnik

unread,
Apr 18, 2011, 11:00:18 AM4/18/11
to robotframe...@googlegroups.com
hi, colleagues


When i get a 'class' attribute its' ok:

KEYWORD: ${fieldType} = SeleniumLibrary.Get Element Attribute //input[@id="lastName"]@class
Documentation:Return value of element attribute.
Start / End / Elapsed:20110418 17:49:52.221 / 20110418 17:49:56.707 / 00:00:04.486
17:49:56.707 INFO ${fieldType} = frm_inputShort

When i get a 'type' attribute it returns error:

KEYWORD: ${fieldType} = SeleniumLibrary.Get Element Attribute //input[@id="lastName"]@type
Documentation:Return value of element attribute.
Start / End / Elapsed:20110418 17:53:19.240 / 20110418 17:53:27.319 / 00:00:08.079
17:53:27.319 FAIL ERROR: Could not find element attribute: //input[@id="lastName"]@type





Maybe i do something wrong but I cannot get a type of given html tag by Get Element Attribute keyword.
if a <select or <input element placed on page how can i get which type of element?

Thanks in advance
Andrew


Pekka Klärck

unread,
Apr 19, 2011, 10:39:43 AM4/19/11
to kolesni...@gmail.com, robotframe...@googlegroups.com
2011/4/18 Andrew Kolesnik <kolesni...@gmail.com>

>
> When i get a 'class' attribute its' ok:
>
[snip]

>
> Maybe i do something wrong but I cannot get a type of given html tag by Get Element Attribute keyword.
> if a <select or <input element placed on page how can i get which type of element?

Since class works I suspect this could be a Selenium issue. Could you
try can you get the type value if you use Selenium IDE? The Selenium
command `Get Element Attribute` ends up using is `getAttribute`.

Cheers,
.peke
--
Agile Tester/Developer/Consultant :: http://eliga.fi
Lead Developer of Robot Framework :: http://robotframework.org

Andrew Kolesnik

unread,
Apr 20, 2011, 8:03:39 AM4/20/11
to robotframe...@googlegroups.com, kolesni...@gmail.com
yes, you are right
it something related with
http://code.google.com/p/selenium/issues/detail?id=850
http://code.google.com/p/selenium/issues/detail?id=674

more over i tried to
Call Selenium Api    getAttribute    //input[@id="lastName"]@type

and got the same result.

What a workaround can be proposed here? hm...

More obvious is to write own RegExp parser function for a while...

Pekka, thanks for reply.

Pekka Klärck

unread,
Apr 25, 2011, 9:05:22 AM4/25/11
to kolesni...@gmail.com, robotframe...@googlegroups.com
2011/4/20 Andrew Kolesnik <kolesni...@gmail.com>:

At least the first isn't too much related because it affects the new
WebDriver based APIs and SeleniumLibrary still uses old Selenium 1.0
APIs (that are still present in Selenium 2.0).

> more over i tried to
> Call Selenium Api    getAttribute    //input[@id="lastName"]@type
>
> and got the same result.

This pretty much confirms that this is a Selenium issue, though. Have
you tested this with different browsers? The problem could be somehow
related to how browsers parse the source code into DOM. Anyway, you
might want to submit an issue about this to Selenium's issue tracker.

> What a workaround can be proposed here? hm...
>
> More obvious is to write own RegExp parser function for a while...

Getting the whole page source and verifying it contains expected
content sounds like a good plan. Notice, though, that the source you
get from Selenium may also differ depending on the browser.

> Pekka, thanks for reply.

Glad I was able to help!

Janne Härkönen

unread,
Apr 27, 2011, 4:39:16 AM4/27/11
to pe...@iki.fi, kolesni...@gmail.com, robotframe...@googlegroups.com
On Mon, Apr 25, 2011 at 4:05 PM, Pekka Klärck <pe...@iki.fi> wrote:
> 2011/4/20 Andrew Kolesnik <kolesni...@gmail.com>:

>> What a workaround can be proposed here? hm...
>>
>> More obvious is to write own RegExp parser function for a while...
>
> Getting the whole page source and verifying it contains expected
> content sounds like a good plan. Notice, though, that the source you
> get from Selenium may also differ depending on the browser.

I recently created a small utility library for verifying content on
HTML pages[1]. It currently only works for local files, but could
easily be extended to also remote files. Verifying attributes of
elements would also be very easy to add.

If you are interested in helping with this approach, feel free to
create an issue in the project pages to get started.

[1] https://github.com/robotframework/HTMLChecker/

thanks,
--J

--
Janne Härkönen | http://reaktor.fi
http://twitter.com/#!/janneharkonen

Reply all
Reply to author
Forward
0 new messages