Hi,
I am new to selenium and we are implementing SeleniumRC with Java in our project. I spent full day to find - how to get node/tag name of the element. Please provide some info.
Following is the example :
//table[@class='DialogForm']//*[contains(@id,'subProject')] according to this xapth I am able to identify element but I have to take action according to type of element, like if it is dropdown menu I ll select option, if it is text input I have to type or click if its radio button.
I tried following but this gives me textof the element:
//table[@class='DialogForm']//*[contains(@id,'subProject')]//*[name()]
Regards,
Chetan
if you want to know whether the input element is a textbox or a radio, you should get the element's 'type' attribute value not the element's tag name or node name, for example:
public void testInputType() throws Exception {
selenium.open("http://www.google.com/");
//assert the search button's type is submit
assertEquals("submit", selenium.getAttribute("btnG@type"));
}
The above answer gives result when the attribute "type" is written in the element, What happen in situation like select(dropdown) which normally does not have "type" attribute.
Hi,
I'm not aware for the Java syntax but in C# it would be
String nodeName = selenium.GetEval("this.page().findElement('<locator>').nodeName")
Where <locator> is your xpath or id or whatever.
After this statement nodeName should contain the name of the html tag, e.g. INPUT, SELECT, DIV, etc.
I hope this helps and you can modify it for Java and use it ![]()
select element also has type attribute, its type is either 'select-one' or 'select-multiple'. but getAttribute command doesn't correctly obtain it. the reture value is always "null"![]()
if your webapp doesn't have any other kinds of form elements whose type value returned by getAttribute is "null", i think you can simply consider "null" as type of select.
Thanks Todor,
getEval works for me too.
But it is very basic need to know element name, Selenium should have function for it.
