Jump to content

Recommended Posts

Posted

Hey guys,

I am new to scripting and no matter what I try, I cannot figure out how to click a button on a website I'm trying to use my script on.

image.png.4c50c60f3e1431d2a010934e7353dc14.png

Below is the code I wrote so far. I kindly ask for help/tips on what I am doing wrong. To my understanding, below should result in the button being clicked and opening a window for selecting a file to be uploaded.

Func Upload()

   Local $oIE = _IECreate("https://puesc.gov.pl/web/puesc/my-documents p_p_id=seap_lf_myDocuments_portlet_WAR_seap_lf_myDocuments_portlet&p_p_lifecycle=0&p_p_state=normal&p_p_mode=view&p_p_col_id=column-1&p_p_col_count=1&_seap_lf_myDocuments_portlet_WAR_seap_lf_myDocuments_portlet_action=renderList&category=draft")
   _IELoadWait($oIE)
   Local $oSubmit = _IEGetObjByName($oIE, "Dodaj")
   Local $hWnd = _IEPropertyGet($oIE, "hwnd")
   _IEAction($oSubmit, "focus")
   ControlSend($hWnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]", "{Enter}")


   ;ControlFocus("Open","","Edit1")
   ;ControlSetText("Open","","Edit1","TEST")
   ;ControlClick("Open","","Button1"

   EndFunc
Posted

The button doesn't have a defined name, so I suspect that you are getting an error on the _IEGetObjByName line. You will need to get the object reference using another method. One option is to use _IETagNameGetCollection to obtain a collection of button elements and then loop through the collection until you find the desired button.

 

Posted
12 minutes ago, VeryGut said:

I have no clue what to do next

First step would be to post your code so that we can see what generated that output. 😏

P.S. If you just took the code from the help file and ran it, that would explain your output above. Try with the following (untested) changes --

#include <IE.au3>
#include <MsgBoxConstants.au3>

Local $oIE = _IEAttach("puesc.gov.pl", "url")

If @error = $_IEStatus_Success Then
    Local $oButtons = _IETagNameGetCollection($oIE, "button")
    Local $sTxt = ""
    For $oButton In $oButtons
        $sTxt &= $oButton.innerText & @CRLF
    Next
    MsgBox($MB_SYSTEMMODAL, "Buttons", "InnerText :" & @CRLF & $sTxt)
EndIf

_IEQuit($oIE)

 

Posted
Func Upload()

   Local $oIE = _IEAttach("https://puesc.gov.pl","url")
   Local $oSubmit = _IEGetObjByName($oIE, "Dodaj dokument ręcznie")

   Local $hWnd = _IEPropertyGet($oIE, "hwnd")

   _IEAction($oSubmit, "click")

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

   _IELinkClickByText($oIE, "Dodaj dokument ręcznie")

   ;ControlFocus("Open","","Edit1")
   ;ControlSetText("Open","","Edit1","TEST")
   ;ControlClick("Open","","Button1"

EndFunc

The above does not seem to be clicking the button, on any of the 3 options I tried. Any idea on what might be the cause?

Posted (edited)

I'm an idiot :D

That works! Thank you kind stranger!

Local $oIE = _IEAttach("https://puesc.gov.pl","url")
Local $hWnd = _IEPropertyGet($oIE, "hwnd")
Local $oButs = _IETagNameGetCollection($oIE, "button")
   
   For $oBut In $oButs
      If StringInStr($oBut.innertext, "Dodaj dokument ręcznie") Then _IEAction($oBut, "click")
   Next

 

Edited by VeryGut
Posted (edited)


There are some more step I need help with.:

1) I am trying to upload a file once the popup window opens for file selection with the following code. None of the two methods work. It does not send the link to the file into the Edit1 box. While trying yesterday I think I was successful with method 1, but it failed once I started working on the code today:

image.png.c01ad4e793c14cf2fe91d479a0465f26.png

;choose the .xml to be uploaded
  
    ;method 1
    ControlFocus("Choose File to Upload","","Edit1")
    ControlSetText("Choose File to Upload","","Edit1","C:\Users\ABC\Desktop\pojedyncze potweirdzenia\1.xml")
    ControlClick("Choose File to Upload","","Button1")
   
   ;method 2
   Send("Edit1","C:\Users\tjalowiec\Desktop\pojedyncze potweirdzenia\1.xml")

2) After successfully uploading the files, they still need to be sent to the system via a drop down list (please see the picture below). The problem is I cannot reference the drop down list using the name of the uploaded file, nor with the name of the drop down list itself with the following:

For $oBut In $oButs
         If StringInStr($oBut.innertext, "- wybierz -") Then _IEFormElementOptionSelect($oBut, "Wyślij")
      Next

 

image.thumb.png.e70d1a89da78088eb1c4a92a03aa2e0e.png

image.thumb.png.3580f03a48401bd05bb09f6d1edadffc.png

Edited by VeryGut
Posted
48 minutes ago, VeryGut said:

I am trying to upload a file once the popup window opens for file selection with the following code. None of the two methods work.

This has been discussed numerous times on the forum. Please take the time to search the forum for the solution.

51 minutes ago, VeryGut said:

The problem is I cannot reference the drop down list using the name of the uploaded file, nor with the name of the drop down list itself with the following

Normally, you would want to use _IEFormElementOptionSelect to select an option from a dropdown listbox.

Posted (edited)

1) problem solved using a second script (complied into .exe), that starts before "click" is performed with _IEAction . Also, because I am an idiot I had this idea to pass variables from one script to another using ClipGet and ClipPut. That is a neat trick!

Func Upload()

$Directory = "ABC"; this is my file directory

   Local $oIE = _IEAttach("https://puesc.gov.pl","url")
   Local $hWnd = _IEPropertyGet($oIE, "hwnd")
   Local $oButs = _IETagNameGetCollection($oIE, "button")
   $aFiles = _FileListToArrayRec($Directory, "*.xml", $FLTAR_FILES)
;Scrip goes through every .xml file to be uploaded under designated folder
For $i=1 To Ubound($aFiles)
   ;open the "Upload document" window
      For $oBut In $oButs
         If StringInStr($oBut.innertext, "Dodaj dokument ręcznie") Then _IEAction($oBut, "click")
         Next
   ClipPut($aFiles[$i])
   ShellExecute("UploadFile.exe")
   ;press the "Browse" button
   Local $oSubmit = _IEGetObjByName($oIE, "docFile")
   _IEAction($oSubmit, "click")

#comments-start
   ;choose the .xml to be uploaded - this script stops once "click" from line 52 is performed. In order to avoid the deadlock, a second script is implemented before execution of line 51, that will bypass the deadlock
   
   #include <MsgBoxConstants.au3>
   #include <IE.au3>
   #include <File.au3>

$Directory = "ABC" ; this is my file directory
$aFiles = _FileListToArrayRec($Directory, "*.xml", $FLTAR_FILES)
   
   Local $FileuUpload = WinGetHandle("Choose File to Upload")
   Local $FileLink = $Directory&"1.xml"
   ControlFocus($FileuUpload,"","Edit1")
   ControlSetText($FileuUpload,"","Edit1",$FileLink)
   ControlClick($FileuUpload,"","Button1")
   
#comments-end

   ;upload the .xml
      For $oBut In $oButs
         If StringInStr($oBut.innertext, "Potwierdź") Then _IEAction($oBut, "click")
         Next
   ;file the form
      For $oBut In $oButs
         If StringInStr($oBut.innertext, "- wybierz -") Then _IEFormElementOptionSelect($oBut, "Wyślij")
         Next
         Sleep(10000)
Next

EndFunc

 

Still working on the second problem

Edited by VeryGut

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.
×
×
  • Create New...