VeryGut Posted March 27, 2019 Posted March 27, 2019 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. 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
Danp2 Posted March 27, 2019 Posted March 27, 2019 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. Latest Webdriver UDF Release Webdriver Wiki FAQs
VeryGut Posted March 27, 2019 Author Posted March 27, 2019 This is the resulting list of _IETagNameGetCollection. I have no clue what to do next :C
Danp2 Posted March 27, 2019 Posted March 27, 2019 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) Latest Webdriver UDF Release Webdriver Wiki FAQs
VeryGut Posted March 27, 2019 Author Posted March 27, 2019 Thanks, it was code from the help file. This is the result of what you proposed:
Danp2 Posted March 27, 2019 Posted March 27, 2019 Ok... you now have a means to get the desired button. You can adjust the above code to compare the innerText to a desired value and then take action once found. Latest Webdriver UDF Release Webdriver Wiki FAQs
VeryGut Posted March 27, 2019 Author Posted March 27, 2019 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?
Danp2 Posted March 27, 2019 Posted March 27, 2019 Yes, because you are still trying to get the button using _IEGetObjByName when the element doesn't have a name. Why haven't you adapted your code to use the _IETagNameGetCollection instead? Latest Webdriver UDF Release Webdriver Wiki FAQs
VeryGut Posted March 27, 2019 Author Posted March 27, 2019 (edited) I'm an idiot 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 March 27, 2019 by VeryGut Danp2 1
VeryGut Posted March 28, 2019 Author Posted March 28, 2019 (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: ;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 Edited March 28, 2019 by VeryGut
Danp2 Posted March 28, 2019 Posted March 28, 2019 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. Latest Webdriver UDF Release Webdriver Wiki FAQs
VeryGut Posted March 28, 2019 Author Posted March 28, 2019 (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! expandcollapse popupFunc 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 March 28, 2019 by VeryGut
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now