Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

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 just 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)

share|improve this question

1 Answer 1

I wrote a javascript snippet as follows after reading replies from the webdriver google group:

wd.execute_script("document.getElementById('allImages').value = '../uploads/b31f8a31-9d4e-49a6-b613-fb902de6a823.jpg';")

Answer from the webdriver google group:

Using the "execute_script" method is the recommended approach in this case.

No, none in WebDriver, since it aims to imitate a user and a user cannot set attributes directly.

share|improve this answer
1  
You can simplify this with this code: image = wd.find_element_by_id("allImages") wd.execute_script(arguments[0].value = '../uploads/b31f8a31-9d4e-49a6-b613-fb902de6a823.jpg';", image) –  Sam Woods Jul 3 '12 at 22:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.