webdriver getAttribute("value") returning null even after setting the value

9,013 views
Skip to first unread message

Pavithra

unread,
Aug 26, 2011, 8:08:17 AM8/26/11
to webdriver, simon.m...@gmail.com
Hi,

I am trying the below scenario for mail application:

1. Open the compose window
2. Identify the body element say(body_element)
3. body_element.sendKeys("This is the sample test");
4. body_element.sendKeys(Keys.Enter);
5. body_element.sendKeys("second line sample");
6. body_element.getAttribute("value")

Here, 6th steps returns null. I read that getAttribute("value")
returns the current value properly even if it is modified after the
page is loaded; so, in this I am expecting that getattribute(value)
should return me the whole value whatever I typed in; however its
returning only null.

Note: I tried just typing only one line and tried getattribute(value);
still returns null.

Any idea why this issue is happening and what is the solution for the
same.

Alternatively, I tried using body_element.getText() returns nothing
and body_element.getValue() throws exception (value attribute not
set).

Please help me out !!

Thanks,
Pavithra

Daniel Wagner-Hall

unread,
Aug 26, 2011, 11:57:48 AM8/26/11
to webd...@googlegroups.com
Please supply a reproduction case; full HTML, javascript, and java.
Ideally reduced to the minimum required to demonstrate the problem.

> --
> You received this message because you are subscribed to the Google Groups "webdriver" group.
> To post to this group, send email to webd...@googlegroups.com.
> To unsubscribe from this group, send email to webdriver+...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/webdriver?hl=en.
>
>

Jim Evans

unread,
Aug 26, 2011, 1:09:11 PM8/26/11
to webdriver
I could be mistaken, but I don't think IE updates the value attribute
until focus leaves the field.

On Aug 26, 11:57 am, Daniel Wagner-Hall <dawag...@gmail.com> wrote:
> Please supply a reproduction case; full HTML, javascript, and java.
> Ideally reduced to the minimum required to demonstrate the problem.
>

Pavithra

unread,
Aug 29, 2011, 1:20:10 AM8/29/11
to webdriver
Below is the html part for the body element:
Also, we could find the line "This is the test mail" (value typed in
the body). However while trying to fetch value; its not fetching.
Note: I am trying in Firefox (as of now)

<div id="ws_widget_Pane_21" class="dijitAlignClient" lang=""
dojoattachpoint="iframePane" layoutalign="client"
dojotype="ws.widget.Pane" dir="" widgetid="ws_widget_Pane_21"
style="left: 0px; top: 67px; right: auto; bottom: auto; width: 526px;
height: 63px;">
<iframe height="100%" width="100%" dojoattachevent="onload:
onIframeLoaded" allowtransparency="true" name="editor_body"
tabindex="104" src="about:blank" dojoattachpoint="iframe">
<html>
<head>
</head>
<body style="color: black; font-size: 10pt; font-family:
Arial,Helvetica,sans-serif;">
<font size="2" face="Arial, Helvetica, sans-serif" color="black">
<div>
<br>
</div>
<div>
This is the test mail
<br>
</div>
<div style="clear: both;"></div>
</font>
</body>
</html>
</iframe>
</div>

Pavithra

unread,
Aug 30, 2011, 7:12:06 AM8/30/11
to webdriver
Hi,
Sorry for the confusion. Problem is when I am trying to get the
content of the iframe, I am not getting the content instead it says
"value attribute not present" for the element.

I fetched element inside the iframe and trying to do
element.getattribute("value") which throws the "value attribute not
found" exception.

Is this expected? or do we have any alternate solution for the same in
case of iframe.

Note: I am fetching the above iframe using
driver.findElement(By.cssSelector("iframe[name='editor_body']");

Sample HTML content of iframe:
<iframe height="100%" width="100%" dojoattachevent="onload:
onIframeLoaded" allowtransparency="true" name="editor_body"
tabindex="104" src="about:blank" dojoattachpoint="iframe">
<html>
<head>
</head>
<body style="color: black; font-size: 10pt; font-family:
Arial,Helvetica,sans-serif;">
<font size="2" face="Arial, Helvetica, sans-serif" color="black">
<div>
</div>
<div>
hello content
<br _moz_dirty="">
how are you
<br _moz_dirty="">
<br _moz_dirty="">
adfjdj
<br _moz_dirty="">
kasjdfkljsd
<br>
</div>
<div style="clear: both;"></div>
</font>
</body>
</html>
</iframe>

Kindly help out to resolve this.

Jim Evans

unread,
Aug 30, 2011, 10:40:57 AM8/30/11
to webdriver
I think you want .getText(). If you're not using an <input> element,
it won't have a value attribute.
> > > > > For more options, visit this group athttp://groups.google.com/group/webdriver?hl=en.- Hide quoted text -
>
> - Show quoted text -

Pavithra

unread,
Sep 5, 2011, 2:03:15 AM9/5/11
to webdriver
I have mentioned the html tag in the above post. Yes, it doesn't have
an <input> element; it's a div element.
So, how to fetch the value of the div element ?

Thanks,
Pavithra
> > > > > > For more options, visit this group athttp://groups.google.com/group/webdriver?hl=en.-Hide quoted text -

Mark Collin

unread,
Sep 5, 2011, 4:40:35 AM9/5/11
to webd...@googlegroups.com
There is no value attribute on a div element...

Do you mean getText() ?

Thanks,
Pavithra

--
This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Pavithra

unread,
Sep 6, 2011, 1:16:43 AM9/6/11
to webdriver
Tried even getText(), but its returning empty string.
I basically wanted the text or value.

Pavithra
> If you have received this email in error please notify postmas...@ardescosolutions.com

Muhil

unread,
Sep 6, 2011, 1:19:48 AM9/6/11
to webd...@googlegroups.com
Hi ,

    Did you try through JSExecutor?


Thanks,
Muhil

To post to this group, send email to webd...@googlegroups.com.

Mark Collin

unread,
Sep 6, 2011, 1:20:57 AM9/6/11
to webd...@googlegroups.com
Have you switched to the iFrame before trying to interact with elements from
it?

Pavithra

--


This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.

If you have received this email in error please notify postm...@ardescosolutions.com

Pavithra

unread,
Sep 6, 2011, 6:46:22 AM9/6/11
to webdriver
I didn't try out any JS executor.
I first fetched the element using css selector with iframe name and
typed the contents into it.
Then, I switched to the iframe and tried to use element.getText();
which returned the empty string.

But I got the solution now as below:
After switching to iframe; I again fetched the new element inside the
frame using xpath: //html/body (since the content is inside iframe/
html/body) and then did newelement.getText() which returned me the
content properly.

Thanks a lot for suggestions !!

Pavithra
> > > > On Aug 29, 10:20 am,Pavithra<pavi...@gmail.com> wrote:
>
> > > > > Below is the html part for the body element:
> > > > > Also, we could find the line "This is the test mail" (value
> > > > > typed in the body). However while trying to fetch value; its not
> fetching
>
> --
> This message contains confidential information and is intended only for the individual named. If you are not the named addressee you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately by e-mail if you have received this e-mail by mistake and delete this e-mail from your system. If you are not the intended recipient you are notified that disclosing, copying, distributing or taking any action in reliance on the contents of this information is strictly prohibited.
>
> If you have received this email in error please notify postmas...@ardescosolutions.com

jerald

unread,
Sep 6, 2011, 4:51:58 AM9/6/11
to webd...@googlegroups.com
When you type some text in the field, it actually types the text and focus remains there. so getAttribute method may return null. Try clicking some where in the body and then execute getText command.
Thanks and Kind Regards
jerald



To post to this group, send email to webd...@googlegroups.com.

priyadarshi Bharat

unread,
Mar 17, 2014, 12:28:34 AM3/17/14
to webd...@googlegroups.com, simon.m...@gmail.com
Hi all,

I am having a similar problem.. ni my case i am referring to a 'Done' button on a web application where 'disabled' attribute is added after the page reloaded. The problem is that the 
.getAttribute("disabled") return a null, while the HTMl is as following:

<input type="submit" ng-disabled="isLocked" ng-click="submitActionPlan()" value="Done" name="submit" disabled="disabled"/>

Please suggest me a solution/the reason why that happens ?
Reply all
Reply to author
Forward
0 new messages