1

Description

I want upload userpic in social network (vk.com) automaticly.

How page looks

In the browser code inspector upload block looks like this:

code in picture

<div class="inline_upload_wrap pointer_wrap _touched">
<input 
    type="file" 
    class="inline_upload" 
    onchange="return ownerPhotoUpload.start(this, event);"
    accept="image/*" 
    data-upload-url="https://pu.vk.com/c633130/upload.php?act=owner_photo&amp;oid=-115785066&amp;square=&amp;_fwadd=-115785066&amp;mid=248870261&amp;server=633130&amp;_origin=https%3A%2F%2Fm.vk.com&amp;_sig=a583bf541a5ebc8676830fca26b049ca" 
    data-base-url="https://pu.vk.com/c633130/" 
    data-static-url="https://pp.vk.me/c633130/">
<a href="/album-115785066_0?act=add&amp;from=profile" class="pm_item profile_photo_upload_wrap"></a>
</div>

What I tried

  • input_elem.send_keys(path) doesn't do anything.
  • send binary file by request.post with cookies from selenium driver and with url that contains in <input data-upload-url="URL">. Response is a string: "security breach"

Why it doesn't work

input has a field onchange="return ownerPhotoUpload.start(this, event);" This function:

start: function(e, t) {
    if (!e || !canUploadFile()) return ownerPhotoUpload.fallback(e, t);
    var a = e.files,
        n = a[0] || !1,
        o = attr(e, "data-upload-url"),
        i = attr(e, "data-base-url"),
        r = attr(e, "data-static-url");
    if (!n) return !1;
    if (!o) return ownerPhotoUpload.fallback(e, t);
    var s = {
        upload_url: o,
        base_url: i,
        static_url: r,
        file: n
    };
    return s.xhr = uploadFile(o, {
        photo: n
    }, {
        onProgress: bind(ownerPhotoUpload.onUploadProgress, s),
        onComplete: bind(ownerPhotoUpload.onUploadComplete, s),
        onError: bind(ownerPhotoUpload.onUploadError, s)
    }), readFile(n, function(e) {
        photoview.updateUpload({
            thumb: e
        })
    }), replace(clone(e), e), photoview.onClose = bind(ownerPhotoUpload.onClose, s), photoview.openUpload({
        src: null
    }), !1
},

It has the same things as href in input. So, I think, that I just have to add or change some data in my request.

What can I do?

  • add some data to request (what data?)
  • do send_keys in other way (what way?)
  • handle a window for picking an image that appers when I click button "Upload a picture" (how to handle it in linux?)
ledu
  • 59
  • 5
  • Can you provide line of code where you try `send_keys()`? – Andersson Mar 02 '16 at 20:09
  • You could try to set the input field's test using JavaScript with one change event, instead of sending the keys with WebDriver (having one change event for each key). Check JavascriptExecutor in Selenium doc + this: http://stackoverflow.com/questions/7609130/set-the-value-of-a-input-field-with-javascript – skandigraun Mar 02 '16 at 20:29
  • I red some materials. Guys write that you can't use js for uploading files for some security reasons. http://stackoverflow.com/questions/14889239/how-to-set-default-value-in-input-type-file-by-using-javascript — @skandigraun – ledu Mar 02 '16 at 21:01
  • I tried: input_elem = driver.find_element_by_class_name("inline_upload").send_keys(PATH) — @Andersson – ledu Mar 02 '16 at 21:02
  • @KhasanKhafizov get any error or just no visible results? – Andersson Mar 02 '16 at 21:09
  • @Andersson yes. nothing happens. no errors – ledu Mar 02 '16 at 21:10
  • @KhasanKhafizov, I tried to upload image on my page into Photos category and after some tricks I finally upload it. So it is not a security issue – Andersson Mar 02 '16 at 21:13
  • @KhasanKhafizov, but I can't understand where you try to upload image file... Does it some public page or group? – Andersson Mar 02 '16 at 21:14
  • @Andersson yeah. sort of – ledu Mar 02 '16 at 21:33

0 Answers0