Set attribute of an element

416 views
Skip to first unread message

SimSel

unread,
Jul 3, 2012, 3:20:15 PM7/3/12
to webd...@googlegroups.com
Hi!

I am trying to automate uploading an image. The uploader is a Flash object and using AutoIt is not an option. So I am trying to work my way around this with webdriver.
The idea is to 'set' the value attribute of the image uploader with a link pointing to an image saved on the server. My question is, is there a method to set the attribute of an element in webdriver? I know there is one to get value (get_attribute) . I am using python + webdriver.

The input field is:

<input type="hidden" value="" name="allImages" id="allImages">

and I have tried :

        image = wd.find_element_by_id("allImages")
        image.value = "http://optimusprime/uploads/b31f8a31-9d4e-49a6-b613-fb902de6a823.jpg"

The script runs without error, but the attribute value is not set. Can anybody please point me to the right way of setting attributes? (if there is one)

Thanks in advance!
S

Peter Gale

unread,
Jul 3, 2012, 3:34:49 PM7/3/12
to webd...@googlegroups.com
No, none in WebDriver, since it aims to imitate a user and a user cannot set attributes directly.

You could execute some javascript, though, and have this set the attribute.


Date: Tue, 3 Jul 2012 12:20:15 -0700
From: snneha...@gmail.com
To: webd...@googlegroups.com
Subject: [webdriver] Set attribute of an element
--
You received this message because you are subscribed to the Google Groups "webdriver" group.
To view this discussion on the web visit https://groups.google.com/d/msg/webdriver/-/X1Zh-MuHMzsJ.
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.

Simon Stewart

unread,
Jul 3, 2012, 4:03:30 PM7/3/12
to webd...@googlegroups.com
Using the "execute_script" method is the recommended approach in this case.

Simon

Snehal Bhat

unread,
Jul 3, 2012, 4:32:08 PM7/3/12
to webd...@googlegroups.com
Thanks Peter,Simon! That was my guess too. Will have to dig in and learn some javascript
328.png
Reply all
Reply to author
Forward
0 new messages