I am trying to get all the attribute associate with the element ,but webdriver does have any api to achieve,so iam trying to do with javaScriptexecutor some thing like this
<input type="hidden" name="_custom__userName" id="_custom__userName" value='CRD.2.13.6User15AOK_BN_F1_U1_TS1_DS1_NORMAL_SUBSET1' />i want this valuetype="hidden" name="_custom__userName" id="_custom__userName" value='CRD.2.13.6User15AOK_BN_F1_U1_TS1_DS1_NORMAL_SUBSET1'so below is the code i am trying ArrayList parentAttributes = (ArrayList) ((JavascriptExecutor)selenium).executeScript( "var s = []; var attrs = arguments[0].attributes; for (var l = 0; l < attrs.length; ++l) { var a = attrs[l]; s.push(a.name + ':' + a.value); } ; return s;", element); but iam getting timeout exception org.openqa.selenium.WebDriverException: null (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 203 milliseconds
The problem is that some attributes are implicitly set, and some need to be explicitly set. If you want to know what attributes have been explicitly set you would have to do something like this:
//The parent tag
WebElement myElement = driver.findElement(By.tagName("div"));
String contents = (String)((JavascriptExecutor)driver).executeScript("return arguments[0].innerHTML;", myElement);
Then you could take contents and pull out the attributes, there are couple ways you could do this:
· Use regex
· Create an XML document from the String contents and then pull out all the attributes
If you want to use regex you would probably want to isolate your tag and pull it out of the string and then you could break it up into an array splitting on whitespace. If you create an XML document it will depends on which XML libraries you use, I’ve found xom.nu to be pretty lightweight and good.
From: seleniu...@googlegroups.com [mailto:seleniu...@googlegroups.com] On Behalf Of gouse basha
Sent: 13 August 2012 11:31
To: seleniu...@googlegroups.com
Subject: [selenium-users] how to get all html attributes for a tag
I am trying to get all the attribute associate with the element ,but webdriver does have any api to achieve,so iam trying to do with javaScriptexecutor some thing like this --