How do I test which element has the focus in Selenium RC?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I couldn’t get the
:focuspseudoclass idea to work, not sure why – targetingcss=#search_input input.textmatched, butcss=#search_input input.text:focusdidn’t? But here is what worked for me:This is using the Python Selenium API, so the
get_element_index()calls are wrappers around the core Selenium command list. Adapt this to your environment. It’s evaluating the element index of the document’s focused element (gotten with a Javascript DOM locator) and the element index of the element you want to test for focus (gotten with an XPath locator.) Also see this question.