Jump to content

Recommended Posts

Posted (edited)

hello everybody 

I need to automate uploading image via Autoit to my wordpress blog 

here is my code 

$url = "https://engnajjar.wordpress.com/wp-admin/media-new.php?browser-uploader"
Local $oIE =_IECreate($url)
Local $async_upload = _IEGetObjById($oIE, "async-upload")
Local $upload_btn = _IEGetObjById($oIE, "html-upload")
_IEAction($async_upload, "click")
Sleep(1000)
$hChoose = WinGetHandle("[CLASS:#32770]")
WinWaitActive($hChoose, "Choose File to Upload", 10)
ControlFocus($hChoose,"","Edit1")
Sleep(1000)
ControlSetText($hChoose, "", "Edit1", "C:\Users\administrator\Pictures\image.jpg")
ControlClick($hChoose, "", "Button1")

when the code open popup upload dialog it can't set image location text in edit box to select image 

the code still wait popup upload dialog although the dialog is active.

when I close the dialog, the code back to work then exit without detect the dialog.

where is the problem in my code please ?

Edited by AlienStar
Posted
23 minutes ago, Danp2 said:

See example 2 in the help file for how to avoid this problem.

 would you provide me the example please?

because I didn't know where it is. 

Posted

He is referring to example 2 in the help file for the _IEAction function.  Just click the link in the quote that he provided.

Posted (edited)

I've edited the code according to example 2 but also not working  :(

Local $oIE =_IECreate($url)
Local $async_upload = _IEGetObjByName($oIE, "async-upload")
Local $hWnd = _IEPropertyGet($oIE, "hwnd")
_IEAction($async_upload, "focus")
ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}") 
WinWait("Choose File to Upload", "")
Sleep(2000)
ControlSend("Choose File to Upload", "", "[CLASS:Edit; INSTANCE:1]", "C:\Users\administrator\Pictures\image.jpg")

 I've replace ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}") with _IEAction($async_upload, "click") to open upload dialog 

but entire my problem is I can't set file link in edit box 

Edited by AlienStar
Posted

Hi there 

I've followed all steps to upload image to wordpress blog but it failed 

$url = "https://engnajjar.wordpress.com/wp-admin/media-new.php?browser-uploader"
Local $oIE =_IECreate($url)
Local $async_upload = _IEGetObjById($oIE, "async-upload")
Local $upload_btn = _IEGetObjById($oIE, "html-upload")
_IEAction($async_upload, "click")
Sleep(1000)
$hChoose = WinGetHandle("[CLASS:#32770]")
WinWaitActive($hChoose, "Choose File to Upload", 10)
ControlFocus($hChoose,"","Edit1")
Sleep(1000)
ControlSetText($hChoose, "", "Edit1", "C:\Users\administrator\Pictures\image.jpg")
ControlClick($hChoose, "", "Button1")

where is the wrong in my code please ?

Posted
33 minutes ago, AlienStar said:

I've edited the code according to example 2 but also not working 

"Doesn't work" isn't enough details to allow us to help you further.

34 minutes ago, AlienStar said:

I've replace ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}") with _IEAction($async_upload, "click") to open upload dialog 

You don't want to do that because the clicking from _IEAction is the source of your problem. The _IEAction(Focus) / ControlSend combo is designed to trigger the button without the side effect of pausing the script.

Posted
6 minutes ago, Danp2 said:

How is this different from your other thread? Also, probably not the gonna get much response on an 8 year old thread.

my friend I need to know where is the wrong although I followed all steps in this code 

Posted
11 minutes ago, Danp2 said:

"Doesn't work" isn't enough details to allow us to help you further.

You don't want to do that because the clicking from _IEAction is the source of your problem. The _IEAction(Focus) / ControlSend combo is designed to trigger the button without the side effect of pausing the script.

my friend I put all code I made and don't know more info to provide 

when I use 

ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

it clicks on upload button not browse button because when I use "Autoit windows information tool" to get the class, it showed me that the upload button and browse button have the same class name which is CLASS:Internet Explorer_Server

both buttons have the same class thats why I use _IEAction($async_upload, "click")

after all that help me please :(

Posted
42 minutes ago, AlienStar said:

when I use 

ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")

it clicks on upload button not browse button

The Enter key is sent to the element with focus. So perhaps your earlier code where you were clicking on $async_upload element was incorrect. <shrug>

Change the prior _IEAction line to focus the correct element and then it should work.

Posted (edited)

$async_upload is the element I have to focus on.

because when I do "inspect element" via browser on "browse button" it shows me this ID "$async_upload".

I found no problem in this step to popup upload dialog .

all what I need is to set the file location in edit box after the dialog popup

Edited by AlienStar
Posted

 

6 minutes ago, Danp2 said:

So now your issue is clicking the correct button in the upload dialog? Post your code so that we can take a look and give feedback.

I've edited the first post 

3 hours ago, AlienStar said:

Hi there 

I've followed all steps to upload image to wordpress blog but it failed 

$url = "https://engnajjar.wordpress.com/wp-admin/media-new.php?browser-uploader"
Local $oIE =_IECreate($url)
Local $async_upload = _IEGetObjById($oIE, "async-upload")
Local $upload_btn = _IEGetObjById($oIE, "html-upload")
_IEAction($async_upload, "click")
Sleep(1000)
$hChoose = WinGetHandle("[CLASS:#32770]")
WinWaitActive($hChoose, "Choose File to Upload", 10)
ControlFocus($hChoose,"","Edit1")
Sleep(1000)
ControlSetText($hChoose, "", "Edit1", "C:\Users\administrator\Pictures\image.jpg")
ControlClick($hChoose, "", "Button1")

where is the wrong in my code please ?

here is the same code I put first 

when the code open popup upload dialog it can't set image location text in edit box to select image 

the code still wait popup upload dialog although the dialog is active.

when I close the dialog, the code back to work then exit without detect the dialog.

 

Posted (edited)
4 hours ago, Danp2 said:

So then your WinWaitActive is wrong. Are you sure the phrase "Choose File to Upload" appears in body of the dialog?

here is the dialog and its window info

 

1.jpg

2.jpg

3.jpg

Edited by AlienStar

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...