How to store id/name/attribute of currently focus element

624 views
Skip to first unread message

Sujata Dwivedi

unread,
Apr 16, 2013, 3:21:58 PM4/16/13
to robotframe...@googlegroups.com

Hi,

On tab focus go to next element on the web page i want to check id of that element is that possible to find id.
I used following command
${active-element}=Execute Javascript document.activeelementid

Regards,
Sujata

Hi-Fi

unread,
Apr 17, 2013, 3:44:48 AM4/17/13
to robotframe...@googlegroups.com
I'm not sure what is the question... 

If it's about getting the ID (as in topic), you can get that with that Javascript By:
${active-element}=Execute Javascript window.document.activeElement.id (Execute Javascript keyword is by default executed in Selenium's context).


Br,
Juho

Sujata Dwivedi

unread,
Apr 17, 2013, 11:26:40 AM4/17/13
to robotframe...@googlegroups.com
Thanks for your command
I tried your command but it gives active element as  none.
Starting test: Demo.Gmail.Scripts.Test suite.Login Page.Scenario1.1Login page.testcase1
20130417 20:51:31.551 :  INFO : Opening browser 'ff' to base url 'https://gmail.com'
20130417 20:51:55.943 :  INFO :
Executing JavaScript:
window.document.activeElement.id
20130417 20:51:56.972 :  INFO : ${active-element} = None

Actually, I want id/name/attribute of currently focused element, for example when we are in login page
then there are two field one is user name and other is password, so when cursor  is on username field ,press tab ,now cursor goes to password field,
So my question is" how to verify that cursor goes to password field not on other field".

Regards,
Sujata


Markus Bernhardt

unread,
Apr 17, 2013, 12:06:29 PM4/17/13
to suja...@gmail.com, robotframe...@googlegroups.com
Hi Sujata,

you are missing a return statement in your JavaScript. Try:

    ${activeElementId}=    Execute JavaScript    return window.document.activeElement.id;    

Works at least for me.
Cheers,
Markus
--
You received this message because you are subscribed to the Google Groups "robotframework-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robotframework-u...@googlegroups.com.
To post to this group, send email to robotframe...@googlegroups.com.
Visit this group at http://groups.google.com/group/robotframework-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Sujata Dwivedi

unread,
Apr 17, 2013, 12:49:05 PM4/17/13
to robotframe...@googlegroups.com
Thanks Markus, its working.

Regards,
Sujata

 

Samuel Fuentes

unread,
Jun 17, 2014, 4:48:37 PM6/17/14
to robotframe...@googlegroups.com
Hello,

I hope someone sees this post.
I got similar code for the same purpose and for some reason does not work with certain elements in the pages such as href:
here is the code robotframework
\ ${activeElementId}=    Execute JavaScript    return document.activeElement.id
this is the html element
<a href="javascript:void(0);" onclick="s_objectID=&quot;javascript:void(0);_1&quot;;return this.s_oc?this.s_oc(e):true"><img src="resources/images/help.png" alt="Help" title="Help"></a>

this is what returns
16:42:32.570INFOExecuting JavaScript: return document.activeElement.id
16:42:32.582INFO${activeElementId} =

thanks
Samuel 
Reply all
Reply to author
Forward
0 new messages