Jump to content
AlienStar

ControlSetText doesn't work in wp image uploading dialog!!!

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

Share this post


Link to post
Share on other sites
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. 

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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 ?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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 

Share this post


Link to post
Share on other sites
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 :(

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

 

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.

 

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
On 8/10/2020 at 3:19 PM, Danp2 said:

Right... that text is found in the window's title, so instead of this --

$hChoose = WinGetHandle("[CLASS:#32770]")
WinWaitActive($hChoose, "Choose File to Upload", 10)

have you tried this?

WinWaitActive("Choose File to Upload", "", 10)

 

sorry for being late

I've tried but nothing changed 

Share this post


Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By learner123
      Hi All,
       
      I am new to this AUTO IT and I have created a script that will open an app,enter pin and copy the code generated to clipboard. My java code call this autoIT script and use the copied generated code from clipboard.
      This works fine when server  window is on focus. My server is an windows server. 
      But when I minimize or disconnect the server, the script opens the app.exe but doesn't copy any value to clipboard.  
      Can anyone help me on this 😐
       
      Run("C:\Program Files (x86)\RSA SecurID Software Token\SecurID.exe")
      Local $hWnd=WinWait("abc - RSA SecurID Token") ; waits until the window is the active window
      $hWin = WinGetHandle("abc - RSA SecurID Token");
      ControlSend($hWnd,"","","1111") ; simulates pressing the Home key
      ControlSend($hWnd,"","","{ENTER}");
      ControlSend($hWnd,"","","^c");
      Sleep(1000) ;
      ControlSend($hWnd,"","","^c");
       
    • By Spartan117
      Hi everyone,
      I wonder if there is a cloud service that can offer a physical server so that AutoIT can turn as it is in a physical machine.
      Thank you
    • By Ascer
      1. Description.
      Automate communication with Gmail API using oAuth 2.0 security. 2. Requirements.
      Google Gmail account. Finished Authorization process. Look here 3. Possibilities.
      ;======================================================================================================================== ; Date: 2018-02-12, 11:46 ; ; Bug Fixs: 2018-02-17, 7:31 -> Fixed problems with adding items to array and minor bugs. ; ; Description: UDF for using Gmail API interface. This UDF requires oAuth.au3 and Gmail account. ; ; Function(s): ; gmailUsersGetProfile() -> Information about your account. ; gmailUsersLabelsList() -> Get all available labels ids. ex. "INBOX", "UNREAD" ; gmailUsersLabelsGet() -> Get information about specific label id. ; gmailUsersMessagesBatchDelete() -> Delete many messages emails by id. ; gmailUsersMessagesBatchModify() -> Set status for many messages ex. "INBOX", "UNREAD" ; gmailUsersMessagesDelete() -> Totaly delete email from ur account. ; gmailUsersMessagesGet() -> Get all information about specific email. ; gmailUsersMessagesList() -> Get list of last ~100 emails. ; gmailUsersMessagesModify() -> Modify single message. ; gmailUsersMessagesTrash() -> Put email in trash. ; gmailUsersMessagesUntrash() -> Restore email from trash. ; gmailUsersMessagesSend() -> Send email to single or group recipients. ; gmailUsersMessagesAttachmentsGet() -> Download attachment by id. ; ; Author(s): Ascer ;======================================================================================================================== 4. Downloads.
      oAuth.au3 Gmail API.au3 5. Examples.
      Sending emails
    • By Spask
      Hi, I'm trying to find a text value inside of a html.
      This is what the line looks like normally:
      <p id="line1" class> <span class="bot">TEXT HERE</span> </p> The text then changes to a non breaking space:
      <p id="line1" class> <span class="bot">&nbsp;</span> </p> And then it changes back to normal text but it's different every time.
      Can I code this so that it grabs the text every time it changes and has a variable that represents it?
      I currently have this inside of my loop:
      $span = .document.getElementsByTagName("span") For $text In $span If $text.value = "&nbsp;" Then Sleep(50) MsgBox(0,0,0) ;messagebox to test if it can be found, but I don't know how to grab the text EndIf Next The problem is that there are many other lines in the html that have the same span but are called "line3", "line5", etc and the one I need is from "line1".
      I will appreciate if anyone can help with this!
    • By TotalAuto
      Howdy All
      I've gone around and around in circles wasting hours trying to fix this problem to no avail so I thought I would try posting for help given there are some real smart people in this forum.
      Background
      I have 5 separate .au3 scripts that all do different basic tasks. For example:
      1.au3 = opens Chrome browser to obtain information from a specific website then closes
      2.au3 = opens an Excel workbook to run a macro then saves and closes
      3.au3 = Open two seperate workbooks and transfers data from one to the other then saves and closes
      4.au3 = .......etc
      5.au3 = .......etc
      These 5 separate scripts, doing completely different tasks, need to each run once per day at 5 different designated times within a day and then close. For example:
      1.au3 = 10am
      2.au3 = 12pm
      3.au3 = 2pm
      4.au3 = 4pm
      5.au3 = 5pm
      Problem
      I can not get these different scripts to reliably run at their designated times. When I manually run these scripts individually by using 'Go F5' they work perfectly. If I convert these scripts to an .exe and manually run each one they work about 98% of time.
      How can I schedule these different .au3 files or associated .exe files to reliably run each day at different times?
      Attempts To Fix The Issue
      1. I have tried converting each .au3 script into their own .exe file and use Window's Task Scheduler to run these .exe files at their designated time but the success rate  of running each .exe in full, to completion, without error is very low at about 30%. Things that commonly go wrong include a browser not opening but movement still continues on the desk top. Other times things just do not happen at all.
      2. I have Windows 7 64 bit and have tried creating and running both (x86) and (x64) .exe files but again reliability problems exist;
      3. I have also tried moving each .exe file to the My Documents folder as I read someone that keeping your files on your desktop ties your files to individual Windows user profiles which can cause AutoIt operating errors. Not sure if this is correct but thought I would try it anyway. It did not fix my issue.
      4. I installed a program called AlwaysUp which supposedly always reliably runs in the background and will reliably execute your AutoIt script or .exe files. Still have significant reliability issues.
      Therefore, can someone please provide advice on how I can get my 5 different .au3 files to run at 5 designated times through the day, every day, without fail? Overtime I will be creating more and more different .au3 files to run certain tasks throughout the day and do not want to create one large AutoIt file that continually runs and attempts to do all the different tasks itself.
      Any help is very appreciated.
      Thanks
      Dan
       
       
×
×
  • Create New...