Search
 
 

Display results as :
 


Rechercher Advanced Search

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Tutorial for how to use storeEval command to get property of an element.

View previous topic View next topic Go down

Tutorial for how to use storeEval command to get property of an element.

Post by Adviser on Thu Aug 13, 2009 6:53 pm

Hello,

This is asimple way to get a property of web elemnt if you knoen the locator of an element.

NOTE: remember if form name is different it will wont work. All code is tested.


Selenium RC Command are:


1. *for checkBox and radio button*


browser.getEval("javascript:{var status = selenium.browserbot.getCurrentWindow().document.form.chkPTOPayment.checked; " +
"var val = selenium.browserbot.getCurrentWindow().document.form.*{color:#00ff00}chkPTOPayment*.*value*;" +
"var form = selenium.browserbot.getCurrentWindow().document.form.chkPTOPayment.form;"+
"var name = selenium.browserbot.getCurrentWindow().document.form.chkPTOPayment.name;"+
"var type = selenium.browserbot.getCurrentWindow().document.form.chkPTOPayment.type;"+
"var click = selenium.browserbot.getCurrentWindow().document.form.chkPTOPayment.click();"+
"var focus = selenium.browserbot.getCurrentWindow().document.form.chkPTOPayment.focus();"+
"var defaultChecked =Selenium.browserbot.getCurrentWindow().document.form.chkPTOPayment.defaultChecked;"+
"alert(status+ \" \" + defaultChecked); }");


2. *for button element*

*note* : add alert box to seevalue of each property
browser.getEval("javascript:{var name = selenium.browserbot.getCurrentWindow().document.form.Image11.name;" +
"var value = selenium.browserbot.getCurrentWindow().document.form.Image11.value;"+
"var type = selenium.browserbot.getCurrentWindow().document.form.Image11.type;"+
"var disabled = selenium.browserbot.getCurrentWindow().document.form.Image11.disabled;"+
"var focus = selenium.browserbot.getCurrentWindow().document.form.Image11.focus();}");


3. *for input field property*

browser.getEval("javascript:{var value = selenium.browserbot.getCurrentWindow().document.form.name.value; " +
"var readOnly = selenium.browserbot.getCurrentWindow().document.form.name.readOnly;"+
"var name = selenium.browserbot.getCurrentWindow().document.form.name.name;"+
"var size = selenium.browserbot.getCurrentWindow().document.form.name.size;"+
"var defaultChecked = selenium.browserbot.getCurrentWindow().document.form.chkPTOPayment.defaultChecked;"+
"var focus = selenium.browserbot.getCurrentWindow().document.form.chkPTOPayment.focus();"+
"var blur = selenium.browserbot.getCurrentWindow().document.form.chkPTOPayment.blur();"+
"alert(defaultChecked +\"\t \" + size); }");

4. *for select list property*

browser.getEval("javascript:{var length = selenium.browserbot.getCurrentWindow().document.form1.cboCurrency.length; " +
"var options = selenium.browserbot.getCurrentWindow().document.form1.cboCurrency.options;"+
"var selectedindex = selenium.browserbot.getCurrentWindow().document.form1.cboCurrency.selectedindex;"+
"var text = selenium.browserbot.getCurrentWindow().document.form1.cboCurrency.text;"+
"var focus = selenium.browserbot.getCurrentWindow().document.form1.cboCurrency.focus();"
"alert(text);"
"}" );

5. *for textArea property*

browser.getEval("javascript:{var name = selenium.browserbot.getCurrentWindow().document.form1.txtDesc_1.name;" +
"var readOnly = selenium.browserbot.getCurrentWindow().document.form1.txtDesc_1.readOnly;"+
"var size = selenium.browserbot.getCurrentWindow().document.form1.txtDesc_1.size;"+
"var type = selenium.browserbot.getCurrentWindow().document.form1.txtDesc_1.type;"+
"var value = selenium.browserbot.getCurrentWindow().document.form1.txtDesc_1.value;"+
"alert( type + \"\t\" + value);"+
"}");




6. *property for form method*

browser.getEval("javascript:{var action = selenium.browserbot.getCurrentWindow().document.form1.action;" +
"var elements =selenium.browserbot.getCurrentWindow().document.form1.elements;"+
"var length =selenium.browserbot.getCurrentWindow().document.form1.length;"+
"var method =selenium.browserbot.getCurrentWindow().document.form1.method;"+
"var submit =selenium.browserbot.getCurrentWindow().document.form1.submit();"+
"alert(elements);"
+"}");


Try to be more creative and used this way to get complex reult and tell me also how to go futher.


Best of luck.
GOD BLESS U ALL
avatar
Adviser
------------------------
------------------------

Posts : 379
Join date : 2009-07-30
Location : India

http://seleniumforum.forumotion.net

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum