views:

74

answers:

4

the question like the title

+1  A: 

The following locator should select the active element in the document:

dom=document.activeElement

If a form field or similar element has focus, then it should be the active element. Hope this helps.

AlistairH
thanks for your help, let me check it. :)
david-shang
i use the following code, but can not get value.String searchValue=selenium.getEval("var test=document.activeElement.id;");
david-shang
+2  A: 

As AlistairH mentions, you can use document.activeElement on most current browsers. To use this in Selenium you can store the active element and compare it to the active element. Below is an example for Selenium IDE, which should point you in the right direction for Selenium RC too.

storeEval | this.browserbot.findElement("name=targetElement").id; | targetElement
storeEval | this.browserbot.getUserWindow().document.activeElement.id; | activeElement
verifyEval | '${targetElement}' | ${activeElement}

Note that the above relies on the element having a unique id assigned.

Dave Hunt
thank you, could i add your msn or skype ? my msn: [email protected] skype: david-shang84
david-shang
A: 

source code:

selenium code: 1 method: String searchValue=selenium.getEval("var test=document.activeElement;");

2 method: String testvalue=selenium.getText("css=#div textarea[class='left_to_right']:focus");

david-shang
A: 

Thanks for your help, i have already resolved the problem. very thanks

david-shang