Jump to content
Sign in to follow this  
_leo_

Click IE object by text

Recommended Posts

Hey there! :)

I am having a problem with clicking a button in IE. As you can see in the code, there would be a class name to click it, but since this button exists several times with exactly the same code, I can only use the "Noch nicht veröffentlicht" to separate it from the others. But this part is just pure text without any classification. 

"<div class="checkmark" data-v-1e5b1f70=""><svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 16 16" data-v-1e5b1f70=""><circle cx="8" cy="8" r="8" data-v-1e5b1f70="" /></svg></div>Noch nicht veröffentlicht"

I was trying to click it with:

#include <IE.au3>
   local $oNNVs = _IEFormGetCollection($oIE2)
   For $oNNV in $oNNVs
       If String($oNNV.innertext) = "Noch nicht veröffentlicht" Then
           _IEAction($oNNV, "click")
       EndIf
    Next

and:

$inputs = $oIE2.document.getElementsByTagName("div")
For $input In $inputs
    If $input.innertext == "Noch nicht veröffentlicht" then
        $input.click()
    EndIf
Next

But nothing seems to work. Thanks for the help!

Share this post


Link to post
Share on other sites

Try something like:
nb: Untested

#include <IE.au3>

Global $oIE = _IECreate("url")
If IsObj($oIE) Then
    $oDivs = _IETagNameGetCollection($oIE, "div")
    If IsObj($oDivs) Then
        For $oDiv In $oDivs
            If IsObj($oDiv) Then
                If $oDiv.className = "checkmark" And $oDiv.innerText = "Noch nicht veröffentlicht" Then
                    _IEAction($oDiv, "click")
                EndIf
            EndIf
        Next
    EndIf
EndIf

 

Share this post


Link to post
Share on other sites
47 minutes ago, Subz said:

Try something like:
nb: Untested

#include <IE.au3>

Global $oIE = _IECreate("url")
If IsObj($oIE) Then
    $oDivs = _IETagNameGetCollection($oIE, "div")
    If IsObj($oDivs) Then
        For $oDiv In $oDivs
            If IsObj($oDiv) Then
                If $oDiv.className = "checkmark" And $oDiv.innerText = "Noch nicht veröffentlicht" Then
                    _IEAction($oDiv, "click")
                EndIf
            EndIf
        Next
    EndIf
EndIf

 

Thank you! Unfortunatly it does not peform a click, although I don't get an error. I think the problem is within the following part:

$oDiv.innerText = "Noch nicht veröffentlicht"

If I delete this part, it makes a click. But on the wrong/last object and obviously not on the "Noch nicht veröffentlicht" one. Maybe because "Noch nicht veröffentlicht" is written on a separate line in the DOM?

Share this post


Link to post
Share on other sites
2 hours ago, Subz said:

Try changing the line to:

If $oDiv.className = "checkmark" And StringStripWS($oDiv.innerText, 7) = "Noch nicht veröffentlicht" Then

Also use ConsoleWrite to show the text for example:
nb: This will show any white space between the "XXXX"

ConsoleWrite("XXXX" & $oDiv.innerText & "XXXX" & @CRLF)

 

Thanks for the suggestion, but it still did not do a click.

What should I expect from the ConsoleWrite? I got a loooooot of text written to the console.

$oDivs = _IETagNameGetCollection($oIE2, "div")
    If IsObj($oDivs) Then
        For $oDiv In $oDivs
            If IsObj($oDiv) Then
                If $oDiv.className = "checkmark" And StringStripWS($oDiv.innerText, 7) = "Noch nicht veröffentlicht" Then
                    _IEAction($oDiv, "click")
                 EndIf
               ConsoleWrite("XXXX" & $oDiv.innerText & "XXXX" & @CRLF)
            EndIf
        Next
    EndIf

At the moment it is looking like this. I am scared that I'll have to use a regular mouseclick. Save me!😃

Share this post


Link to post
Share on other sites

I think the problem is that the innertext is OUTSIDE the "checkmark".  The classname should be "item".  Modify it accordingly and add an ExitLoop after the click...

Share this post


Link to post
Share on other sites
1 hour ago, Nine said:

I think the problem is that the innertext is OUTSIDE the "checkmark".  The classname should be "item".  Modify it accordingly and add an ExitLoop after the click...

Yeeeaahhh! That did it!! Thank you so much:thumbsup:

Share this post


Link to post
Share on other sites
1 hour ago, _leo_ said:

Yeeeaahhh! That did it!! Thank you so much:thumbsup:

Man, you have found a way to do it without me giving you code, congrats...I am proud of you

Edited by Nine

Share this post


Link to post
Share on other sites

@_Leo_  Sorry didn't see that the checkmark div was closed, I need to update my glasses :blink:.  Just for future reference try posting the parent tags along with the item you're trying to manipulate, as it will help us to replicate the code, to help with the solution.

Share this post


Link to post
Share on other sites
On 7/20/2019 at 2:52 PM, Danp2 said:

Suggest that you post a larger segment of HTML or the URL, if possible.

Hey @Danp2

I figured out, that the website I am trying to automate is no longer working with IE. So I decided to rewriete my script to Webdriver UDF for Google Chrome. And since you seem like the "pro" with the wedriver, I'd love to ask for you help. ☺️

My new code is:

#include "wd_core.au3"
    #include "wd_helper.au3"
    
    Global $sSession, $sSession2
    Global $sDesiredCapabilities
    
     SetupChrome()
   _WD_Startup()
   
    $sSession = _WD_CreateSession($sDesiredCapabilities)
   _WD_Navigate($sSession, "url") 
   
   _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//*[text()='Noch nicht veröffentlicht']") ;Noch Nicht Veröffnetlicht
   $oNNV = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[(text(),'Noch nicht veröffentlicht')]")
   _WD_ElementAction($sSession, $oNNV, 'click')
   
   ;more code....

 

 Is it possible to click the element with the Webdriver? I am getting the following result: 

I thought the issue could be with the "ö", but it didnt work when I deleted "veröffentlicht".. Please let me know if you have any suggestions.

 

Quote

__WD_Post: URL=HTTP://127.0.0.1:9515/session/749bb00d8d317df99583768cc1b53d83/element; $sData={"using":"xpath","value":"//*[text()='Noch nicht veröffentlicht']"}
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"b5a42b27-819c-4b64-b917-795802d8c799"}}
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"b5a42b27-819c-4b64-b917-795802d8c799"}}
_WD_WaitElement ==> Success
__WD_Post: URL=HTTP://127.0.0.1:9515/session/749bb00d8d317df99583768cc1b53d83/element; $sData={"using":"xpath","value":"//*[(text(),'Noch nicht veröffentlicht')]"}
__WD_Post: StatusCode=400; ResponseText={"value":{"error":"invalid selector","message":"invalid selector: Unable to locate an element with the xpath expression //*[(text(),'Noch nicht veröffentlicht')] because of the following error:\nSyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[(text(),'Noch nicht veröffentlicht')]' is not a valid XPath expression.\n  (Session info: chrome=75.0.3770.142)","stacktrace":"Backtrace:\n\tOrdinal0 [0x01321B43+1448771]\n\tOrdinal0 [0x012A5A31+940593]\n\tOrdinal0 [0x01232293+467603]\n\tOrdinal0 [0x01233E03+474627]\n\tOrdinal0 [0x01233CF2+474354]\n\tOrdinal0 [0x011D624B+90699]\n\tOrdinal0 [0x011EF520+193824]\n\tOrdinal0 [0x011E7180+160128]\n\tOrdinal0 [0x011EE36B+189291]\n\tOrdinal0 [0x011E6FEB+159723]\n\tOrdinal0 [0x011D09F6+68086]\n\tOrdinal0 [0x011D1990+72080]\n\tOrdinal0 [0x011D1929+71977]\n\tGetHandleVerifier [0x01462E8C+1172172]\n\tGetHandleVerifier [0x013BFE55+504469]\n\tGetHandleVerifier [0x013BFBF0+503856]\n\tOrdinal0 [0x0132C9C8+1493448]\n\tGetHandleVerifier [0x013C062A+506474]\n\tOrdinal0 [0x012B7156+1012054]\n\tOrdinal0 [0x012B6FCF+1011663]\n\tOrdinal0 [0x012C135B+1053531]\n\tOrdinal0 [0x012C14C3+1053891]\n\tOrdinal0 [0x012C04F5+1049845]\n\tBaseThreadInitThunk [0x765D8494+36]\n\tRtlAreBitsSet [0x778C41C8+136]\n\tRtlAreBitsSet [0x778C4198+88]\n"}}
_WD_FindElement: {"value":{"error":"invalid selector","message":"invalid selector: Unable to locate an element with the xpath expression //*[(text(),'Noch nicht veröffentlicht')] because of the following error:\nSyntaxError: Failed to execute 'evaluate' on 'Document': The string '//*[(text(),'Noch nicht veröffentlicht')]' is not a valid XPath expression.\n  (Session info: chrome=75.0.3770.142)","stacktrace":"Backtrace:\n\tOrdinal0 [0x01321B43+1448771]\n\tOrdinal0 [0x012A5A31+940593]\n\tOrdinal0 [0x01232293+467603]\n\tOrdinal0 [0x01233E03+474627]\n\tOrdinal0 [0x01233CF2+474354]\n\tOrdinal0 [0x011D624B+90699]\n\tOrdinal0 [0x011EF520+193824]\n\tOrdinal0 [0x011E7180+160128]\n\tOrdinal0 [0x011EE36B+189291]\n\tOrdinal0 [0x011E6FEB+159723]\n\tOrdinal0 [0x011D09F6+68086]\n\tOrdinal0 [0x011D1990+72080]\n\tOrdinal0 [0x011D1929+71977]\n\tGetHandleVerifier [0x01462E8C+1172172]\n\tGetHandleVerifier [0x013BFE55+504469]\n\tGetHandleVerifier [0x013BFBF0+503856]\n\tOrdinal0 [0x0132C9C8+1493448]\n\tGetHandleVerifier [0x013C062A+506474]\n\tOrdinal0 [0x012B7156+1012054]\n\tOrdinal0 [0x012B6FCF+1011663]\n\tOrdinal0 [0x012C135B+1053531]\n\tOrdinal0 [0x012C14C3+1053891]\n\tOrdinal0 [0x012C04F5+1049845]\n\tBaseThreadInitThunk [0x765D8494+36]\n\tRtlAreBitsSet [0x778C41C8+136]\n\tRtlAreBitsSet [0x778C4198+88]\n"}}
_WD_FindElement ==> Webdriver Exception: HTTP status = 400
__WD_Post: URL=HTTP://127.0.0.1:9515/session/749bb00d8d317df99583768cc1b53d83/element//click; $sData={"id":""}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Element_id length is invalid\n  (Session info: chrome=75.0.3770.142)","stacktrace":"Backtrace:\n\tOrdinal0 [0x01321B43+1448771]\n\tOrdinal0 [0x012A5A31+940593]\n\tOrdinal0 [0x01232293+467603]\n\tOrdinal0 [0x011D5DA0+89504]\n\tOrdinal0 [0x011D7056+94294]\n\tOrdinal0 [0x011D2602+75266]\n\tOrdinal0 [0x011E714D+160077]\n\tOrdinal0 [0x011D23C6+74694]\n\tOrdinal0 [0x011E7361+160609]\n\tOrdinal0 [0x011EE36B+189291]\n\tOrdinal0 [0x011E6FEB+159723]\n\tOrdinal0 [0x011D09F6+68086]\n\tOrdinal0 [0x011D1990+72080]\n\tOrdinal0 [0x011D1929+71977]\n\tGetHandleVerifier [0x01462E8C+1172172]\n\tGetHandleVerifier [0x013BFE55+504469]\n\tGetHandleVerifier [0x013BFBF0+503856]\n\tOrdinal0 [0x0132C9C8+1493448]\n\tGetHandleVerifier [0x013C062A+506474]\n\tOrdinal0 [0x012B7156+1012054]\n\tOrdinal0 [0x012B6FCF+1011663]\n\tOrdinal0 [0x012C135B+1053531]\n\tOrdinal0 [0x012C14C3+1053891]\n\tOrdinal0 [0x012C04F5+1049845]\n\tBaseThreadInitThunk [0x765D8494+36]\n\tRtlAreBitsSet [0x778C41C8+136]\n\tRtlAreBitsSet [0x778C4198+88]\n"}}
_WD_ElementAction: {"value":{"error":"no such element","message":"no such element: Element_id length is invalid\n  (Ses...
_WD_ElementAction ==> Webdriver Exception: {"value":{"error":"no such element","message":"no such element: Element_id length is invalid\n  (Session info: chrome=75.0.3770.142)","stacktrace":"Backtrace:\n\tOrdinal0 [0x01321B43+1448771]\n\tOrdinal0 [0x012A5A31+940593]\n

 

Share this post


Link to post
Share on other sites

$oNNV = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[(text(),'Noch nicht veröffentlicht')]")

 the comma in text(),'Noch' is the problem , use ' = ' as u did in _WD_WaitElement

 

Share this post


Link to post
Share on other sites

Thanks you for taking time! I appreciate it. @Network_Guy @Danp2

I tried both of your suggestions, but I keep getting weird errors. Like this:

Quote

 ==> Error parsing function call.:
_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='item' and contains(text(), 'Noch nicht veröffentlicht')]"
_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, ^ ERROR
>Exit code: 1    Time: 28.58

I dont know what is wrong with the ". I replaced it with single quotaition marks ', but then I got this error:

Quote

==> Unable to parse line.: 
_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, '//div[@class='item' and contains(text(), 'Noch nicht veröffentlicht')]' 
_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, '//div[@class='item' and contains(text(), 'Noch nicht ver^ ERROR
>Exit code: 1    Time: 0.3491

So I tried to remove the "veröffentlicht", and... tadaaaaaa... the next error.

Quote

 ==> Error parsing function call.:
_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, '//div[@class='item' and contains(text(), 'Noch nicht')]'
_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, '//div[@class='item' and contains(text(), 'Noch nicht^ ERROR

Thanks for helping!

Share this post


Link to post
Share on other sites

You clearly didn't read what he said:

5 hours ago, Network_Guy said:

$oNNV = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[(text(),'Noch nicht veröffentlicht')]")

 the comma in text(),'Noch' is the problem , use ' = ' as u did in _WD_WaitElement

 

You kept the comma in your script.

Change it to:

$oNNV = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[(text()='Noch nicht veröffentlicht')]")

 

Share this post


Link to post
Share on other sites

Thanks! @Davidowicza Ohh.. That's embarrassing😄

Unfortunatly I am getting the same error after changing:

Quote

_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='item' and contains(text()='Noch nicht veröffentlicht')]"
_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, ^ ERROR

so i guess there is still something invalid..

and with the following I am getting this: "//*[(text()='?Noch nicht veröffentlic?ht')]" even though there are no question marks in my code. so strange..

_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//*[(text()='Noch nicht veröffentlicht')]") ;Noch Nicht Veröffnetlicht
   $oNNV = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[(text()='Noch nicht veröffentlicht')]")
   _WD_ElementAction($sSession, $oNNV, 'click')
Quote

__WD_Post: URL=HTTP://127.0.0.1:9515/session/ea5c17a97acf731ef72f9ba6bc9d49f4/element; $sData={"using":"xpath","value":"//*[(text()='?Noch nicht veröffentlic?ht')]"}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//*[(text()='?Noch nicht veröffentlic?ht')]\"}\n  (Session info: chrome=75.0.3770.142)","stacktrace":"Backtrace:\n\tOrdinal0 [0x013A1B43+1448771]\n\tOrdinal0 [0x01325A31+940593]\n\tOrdinal0 [0x012B2293+467603]\n\tOrdinal0 [0x01256463+91235]\n\tOrdinal0 [0x0126F520+193824]\n\tOrdinal0 [0x01267180+160128]\n\tOrdinal0 [0x0126E36B+189291]\n\tOrdinal0 [0x01266FEB+159723]\n\tOrdinal0 [0x012509F6+68086]\n\tOrdinal0 [0x01251990+72080]\n\tOrdinal0 [0x01251929+71977]\n\tGetHandleVerifier [0x014E2E8C+1172172]\n\tGetHandleVerifier [0x0143FE55+504469]\n\tGetHandleVerifier [0x0143FBF0+503856]\n\tOrdinal0 [0x013AC9C8+1493448]\n\tGetHandleVerifier [0x0144062A+506474]\n\tOrdinal0 [0x01337156+1012054]\n\tOrdinal0 [0x01336FCF+1011663]\n\tOrdinal0 [0x0134135B+1053531]\n\tOrdinal0 [0x013414C3+1053891]\n\tOrdinal0 [0x013404F5+1049845]\n\tBaseThreadInitThunk [0x765D8494+36]\n\tRtlAreBitsSet [0x778C41C8+136]\n\tRtlAreBitsSet [0x778C4198+88]\n"}}
_WD_FindElement: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//*[(text()='?Noch nicht veröffentlic?ht')]\"}\n  (Session info: chrome=75.0.3770.142)","stacktrace":"Backtrace:\n\tOrdinal0 [0x013A1B43+1448771]\n\tOrdinal0 [0x01325A31+940593]\n\tOrdinal0 [0x012B2293+467603]\n\tOrdinal0 [0x01256463+91235]\n\tOrdinal0 [0x0126F520+193824]\n\tOrdinal0 [0x01267180+160128]\n\tOrdinal0 [0x0126E36B+189291]\n\tOrdinal0 [0x01266FEB+159723]\n\tOrdinal0 [0x012509F6+68086]\n\tOrdinal0 [0x01251990+72080]\n\tOrdinal0 [0x01251929+71977]\n\tGetHandleVerifier [0x014E2E8C+1172172]\n\tGetHandleVerifier [0x0143FE55+504469]\n\tGetHandleVerifier [0x0143FBF0+503856]\n\tOrdinal0 [0x013AC9C8+1493448]\n\tGetHandleVerifier [0x0144062A+506474]\n\tOrdinal0 [0x01337156+1012054]\n\tOrdinal0 [0x01336FCF+1011663]\n\tOrdinal0 [0x0134135B+1053531]\n\tOrdinal0 [0x013414C3+1053891]\n\tOrdinal0 [0x013404F5+1049845]\n\tBaseThreadInitThunk [0x765D8494+36]\n\tRtlAreBitsSet [0x778C41C8+136]\n\tRtlAreBitsSet [0x778C4198+88]\n"}}
_WD_FindElement ==> No match: HTTP status = 404

 

 

 

 

Edited by _leo_

Share this post


Link to post
Share on other sites

Thanks! I got the syntax error out of the way after rewriting 100 times, restarting autoit, and rebooting... 

Everything would work fine.. but I am getting a message that the element is not clickable. I figured out, that there is an other element with the same text name and the script tries to refer to the wrong one. 

Quote

"error":"element click intercepted","message":"element click intercepted: Element \u003Cspan data-v-7abc0274=\"\" class=\"text-truncate\">...\u003C/span> is not clickable at point

 

So i guess I have to get the classname in there aswell, to identify it completly (with the suggestion from @Danp2.) Therefore my code looks like this. And somehow the previous error is gone, but a new Syntax error has occured.

_WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='item' and contains(text()='Noch nicht veröffentlicht')]")
    $NNV = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@class='item' and contains(text()='Noch nicht veröffentlicht')]")
    _WD_ElementAction($sSession, $NNV, 'click')
Quote

_WD_FindElement: {"value":{"error":"invalid selector","message":"invalid selector: Unable to locate an element with the xpath expression //div[@class='item' and contains(text()='Noch nicht veröffentlicht')] because of the following error:\nSyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[@class='item' and contains(text()='Noch nicht veröffentlicht')]' is not a valid XPath expression.\n  (Session info: chrome=75.0.3770.142)","stacktrace":"Backtrace:\n\tOrdinal0 

I read this line a million times. I dont see a syntax mistake... Please someone buy me new eyes🧐

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By mLipok
      In the past there was many questions about how to: "Automatic file upload using without user interaction"

      https://www.autoitscript.com/forum/topic/92907-ie-8-input-namenomfic-typefile-idnomfic/
      https://www.autoitscript.com/forum/topic/116899-cant-automate-input-typefile-tag-in-ie/?tab=comments#comment-815478
      https://www.autoitscript.com/forum/topic/14883-input-typefile/
      https://www.autoitscript.com/forum/topic/188708-how-to-set-the-value-of-an-input-typefile-element/
      https://www.autoitscript.com/forum/topic/91513-how-can-i-auto-set-file-path-for-input-file-in-ie/
      https://www.autoitscript.com/forum/topic/116899-cant-automate-input-typefile-tag-in-ie/
      https://www.autoitscript.com/forum/topic/169190-how-to-script-file-upload-button/
      https://www.autoitscript.com/forum/topic/145327-how-to-deal-with-ie-window-for-upload-a-fileinput-typefile/
      https://www.autoitscript.com/forum/topic/140482-internet-explorer-input-file-problem/
       
      I found solution here: 
      https://stackoverflow.com/questions/33253517/upload-a-file-via-input-input-in-html-form-with-vba
      and:
      https://www.motobit.com/tips/detpg_uploadvbsie/
      And I translate this code to AutoIt3 code:
      ; Upload file using http protocol And multipart/form-data ; v1.01 ; 2001 Antonin Foller, PSTRUH Software Global $oErrorHandler = ObjEvent("AutoIt.Error", _ErrFunc) do_vbsUpload() Func do_vbsUpload() #cs ; We need at least two arguments (File & URL) ConsoleWrite('- ' & @ScriptLineNumber & @CRLF) If $CmdLine[0] < 2 Then InfoEcho() ConsoleWrite('- ' & @ScriptLineNumber & @CRLF) ; Are some required objects missing? If StringInStr(CheckRequirements(), "Error") > 0 Then InfoEcho() ConsoleWrite('- ' & @ScriptLineNumber & @CRLF) Local $s_FileName, $s_DestURL, $s_FieldName $s_FieldName = "FileField" ; Default field name For $i_argCounter = 1 To $CmdLine[0] ConsoleWrite('+ '& $i_argCounter& ' >> ' & $CmdLine[$i_argCounter] & @CRLF) Select Case $i_argCounter = 1 ;~ $s_FileName = $CmdLine[$i_argCounter] $s_FileName = @ScriptFullPath Case $i_argCounter = 2 $s_DestURL = $CmdLine[$i_argCounter] Case $i_argCounter = 3 $s_FieldName = $CmdLine[$i_argCounter] EndSelect Next UploadFile($s_DestURL, $s_FileName, $s_FieldName) #ce UploadFile('http://www.dobeash.com/test.html', @ScriptFullPath, 'fileExample') EndFunc ;==>do_vbsUpload ; ******************* upload - begin ; Upload file using input type=file Func UploadFile($s_DestURL, $s_FileName, $s_FieldName) ; Boundary of fields. ; Be sure this string is Not In the source file Const $Boundary = "---------------------------0123456789012" ; Get source file As a binary data. Local $d_FileContents = GetFile($s_FileName) ; Build multipart/form-data document Local $s_FormData = BuildFormData($d_FileContents, $Boundary, $s_FileName, $s_FieldName) ; Post the data To the destination URL IEPostBinaryRequest($s_DestURL, $s_FormData, $Boundary) EndFunc ;==>UploadFile ; Build multipart/form-data document with file contents And header info Func BuildFormData($d_FileContents, $Boundary, $s_FileName, $s_FieldName) Const $s_ContentType = "application/upload" ; The two parts around file contents In the multipart-form data. Local $s_Pre = "--" & $Boundary & @CRLF & mpFields($s_FieldName, $s_FileName, $s_ContentType) Local $s_Po = @CRLF & "--" & $Boundary & "--" & @CRLF ; Build form data using recordset binary field Const $i_adLongVarBinary = 205 Local $oRS = ObjCreate("ADODB.Recordset") ; https://docs.microsoft.com/en-us/sql/ado/reference/ado-api/append-method-ado?view=sql-server-ver15 $oRS.Fields.Append("b", $i_adLongVarBinary, StringLen($s_Pre) + BinaryLen($d_FileContents) + StringLen($s_Po)) $oRS.Open() $oRS.AddNew() ; Convert Pre string value To a binary data Local $i_LenData = StringLen($s_Pre) $oRS("b").AppendChunk(StringToMB($s_Pre) & StringToBinary(Chr(0))) $s_Pre = $oRS("b").GetChunk($i_LenData) $oRS("b") = "" ; Convert Po string value To a binary data $i_LenData = StringLen($s_Po) $oRS("b").AppendChunk(StringToMB($s_Po) & StringToBinary(Chr(0))) $s_Po = $oRS("b").GetChunk($i_LenData) $oRS("b") = "" ; Join Pre & $d_FileContents & Po binary data $oRS("b").AppendChunk($s_Pre) $oRS("b").AppendChunk($d_FileContents) $oRS("b").AppendChunk($s_Po) $oRS.Update() Local $s_FormData = $oRS("b") $oRS.Close() Return $s_FormData EndFunc ;==>BuildFormData ; sends multipart/form-data To the URL using IE Func IEPostBinaryRequest($s_URL, $s_FormData, $Boundary) ; Create InternetExplorer Local $oIE = ObjCreate("InternetExplorer.Application") ; You can uncoment Next line To see form results $oIE.Visible = True ; Send the form data To $s_URL As POST multipart/form-data request $oIE.Navigate($s_URL, '', '', $s_FormData, _ "Content-Type: multipart/form-data; boundary=" & $Boundary & @CRLF) While $oIE.Busy Wait(1, "Upload To " & $s_URL) WEnd ; Get a result of the script which has received upload ;~ On Error Resume Next Local $s_IE_InnerHTML = $oIE.Document.body.innerHTML MsgBox(0, 'TEST #' & @CRLF & @ScriptLineNumber, $s_IE_InnerHTML) $oIE.Quit() Return $s_IE_InnerHTML EndFunc ;==>IEPostBinaryRequest ; Infrormations In form field header. Func mpFields($s_FieldName, $s_FileName, $s_ContentType) Local $s_MPTemplate = _ ; template For multipart header 'Content-Disposition: form-data; name="{field}";' & _ 'FileName="{file}"' & @CRLF & _ 'Content-Type: {ct}' & @CRLF & @CRLF & _ '' Local $s_Out $s_Out = StringReplace($s_MPTemplate, "{field}", $s_FieldName) $s_Out = StringReplace($s_Out, "{file}", $s_FileName) $s_Out = StringReplace($s_Out, "{ct}", $s_ContentType) Return $s_Out EndFunc ;==>mpFields Func Wait($i_Seconds, $s_Message) MsgBox(64, '', $s_Message, $i_Seconds) EndFunc ;==>Wait ; Returns file contents As a binary data Func GetFile($s_FileName) Local $oStream = ObjCreate("ADODB.Stream") $oStream.Type = 1 ; Binary $oStream.Open() $oStream.LoadFromFile($s_FileName) Local $d_GetFile = $oStream.Read() $oStream.Close() Return $d_GetFile EndFunc ;==>GetFile ; Converts OLE string To multibyte string Func StringToMB($S) Local $I, $B For $I = 1 To StringLen($S) $B &= StringToBinary(Asc(StringMid($S, $I, 1))) Next Return $B EndFunc ;==>StringToMB ; ******************* upload - end ; ******************* Support ; Basic script info Func InfoEcho() Local $sMsg = _ "Upload file using http And multipart/form-data" & @CRLF & _ "Copyright (C) 2001 Antonin Foller, PSTRUH Software" & @CRLF & _ "use" & @CRLF & _ "[cscript|wscript] fupload.vbs file $s_URL [fieldname]" & @CRLF & _ " file ... Local file To upload" & @CRLF & _ " $s_URL ... $s_URL which can accept uploaded data" & @CRLF & _ " fieldname ... Name of the source form field." & @CRLF & _ @CRLF & CheckRequirements() & @CRLF & _ "" ConsoleWrite('! ' & $sMsg & @CRLF) EndFunc ;==>InfoEcho ; Checks If all of required objects are installed Func CheckRequirements() Local $sMsg = _ "This script requires some objects installed To run properly." & @CRLF & _ CheckOneObject("ADODB.Recordset") & @CRLF & _ CheckOneObject("ADODB.Stream") & @CRLF & _ CheckOneObject("InternetExplorer.Application") & @CRLF & _ "" Return $sMsg ; $sMsgBox $sMsg EndFunc ;==>CheckRequirements ; Checks If the one object is installed. Func CheckOneObject($sClassName) Local $sMsg ObjCreate($sClassName) If @error = 0 Then $sMsg = "OK" Else $sMsg = "Error:" & @error EndIf Return $sClassName & " - " & $sMsg EndFunc ;==>CheckOneObject ; ******************* Support - end ; User's COM error function. Will be called if COM error occurs Func _ErrFunc(ByRef $oError) ; Do anything here. ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc  
      But I miss something and the code not works as intendend.
      Please join and contribute, in solving this issue, as this will be handy for entire community.
      @mLipok
       
      btw.
      I think that this may be realated to ChrB() which I simply translate to StringToBinary()
      Especialy this :
      StringToBinary(Chr(0))) could be the main issue.
      But for now I'm tired and going to sleep.
      Hope maybe tomorrow somebody solve this issue.
       
    • By Deshanur
      Am trying to automate injecting credential on the login form for all kind of Web application for IE. I know how to identify the form name by viewing the source code and using the method - _IEFormGetObjByName($ie, $form_Name).
      I would like to know how to identify or get the form object for the web app where there is no form name tag for example below, for the is I have used - _IEFormGetCollection($ie, 0) to get the form object.
      My Question is does it work for all kind of application "_IEFormGetCollection($ie, 0)" how to identify Index value? is it always 0? is there any better solution?
      The final solution am looking for is find out form object, get the username, password field and inject credential and submit the form.
      How to find out index value? for the forms which does not have form name field.
      $login_form = _IEFormGetCollection($ie, 0) $email_field = _IEFormElementGetObjByName($login_form, $form_UserName) $pass_field = _IEFormElementGetObjByName($login_form, $form_password) $login_button = _IEFormElementGetObjByName($login_form, $form_submitbutton) _IEFormElementSetValue($email_field, $CmdLine[2]) _IEFormElementSetValue($pass_field, $CmdLine[3]) ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]","{Enter}") OR This works fine if the form has form name. $login_form = _IEFormGetObjByName($ie, $form_Name) $email_field = _IEFormElementGetObjByName($login_form, $form_UserName) $pass_field = _IEFormElementGetObjByName($login_form, $form_password) $login_button = _IEFormElementGetObjByName($login_form, $form_submitbutton) _IEFormElementSetValue($email_field, $CmdLine[2]) _IEFormElementSetValue($pass_field, $CmdLine[3]) ControlSend($hwnd, "", "[CLASS:Internet Explorer_Server; INSTANCE:1]","{Enter}")
    • By devilspride
      The following code creates a IE blank window
      Local $oIE = _IECreate()  
      But when i use Navigate to the URL, it open the URL in Microsoft Edge instead if IE.
      _IENavigate($oIE,$url)  
      What should i do to navigate in IE.
      Complete code :
      #include <MsgBoxConstants.au3> #include <WinAPIFiles.au3> #include <IE.au3> #Region TESTING Local $url = 'https://www.youtube.com' Local $oIE = _IECreate() _IENavigate($oIE,$url) #EndRegion Console Output
      IE.au3 T3.0-2 Error from function _IELoadWait, $_IESTATUS_ClientDisconnected (-2147023174, Browser has been deleted prior to operation.)  
      I have searched the forums but did not find such kind of post.
      Other posts were describing How to use Edge using Web driver selenium.
       
      Edit: I am working in Windows10. Recently many changes have been done by Microsoft to IE and Microsoft Edge. (2020)
      Earlier in 2019 this was working fine.
    • By Zaoka
      I'm trying to create script that would login on my SAP WEBI "web page" and replace some uploaded excel files. But i'm having problem on even the log in.
      These are user fill elements with Firefox Inspector
      <input type="text" id="_id0:logon:CMS" name="_id0:logon:CMS"> <input type="text" id="_id0:logon:USERNAME" name="_id0:logon:USERNAME"> <input type="password" id="_id0:logon:PASSWORD" name="_id0:logon:PASSWORD"> LogOnButton
      <input type="submit" id="_id0:logon:logonButton" value="Log On" class="logonButtonNoHover logon_button_no_hover" onmouseover="this.className = 'logonButtonHover logon_button_hover';" onmouseout="this.className = 'logonButtonNoHover logon_button_no_hover';">  
       
      My example, I tried _IEGetObjByName and _IEGetObjById but the script only open page but will not even fill out the form
        #include <IE.au3> Call("signIn") Func signIn() Global $oIE = _IECreate("http://192.xxx.xxx.xx:xxx/BOE/BI") Sleep (5000) Local $server = _IEGetObjByName($oIE, "_id0:logon:CMS") Local $username = _IEGetObjByName($oIE, "_id0:logon:USERNAME") Local $password = _IEGetObjByName($oIE, "_id0:logon:PASSWORD") Local $button = _IEGetObjById($oIE, "_id0:logon:logonButton") _IEFormElementSetValue($server, "TestServer:1000") _IEFormElementSetValue($username, "MyUserName") _IEFormElementSetValue($password, "MyPass") ; THIS PART ABOUT BUTTON CLICK I DONT UNDERSTAND AT ALL $sSelector = "body > div:nth-of-type(2) > div > div:nth-of-type(3) > div > table > tbody > tr > td > table > tbody > tr > td > table > tbody > tr:nth-of-type(1) > td > div > div:nth-of-type(1) > form > div:nth-of-type(5) > button" $signInUC = $oIE.document.QuerySelector($sSelector) _IEAction($signInUC, "click") EndFunc ;==>signIn  
      I would be very grateful for any help
    • By adityaparakh
      Hello ,

      A website I am trying to login with my credentials.
      And retrieve the cookie into a text file.
      Unable to do so.
      Is it that certain,  Httponly , type - are not allowed to be fetched.

      Then further ,
      I will be checking every 5 minutes if my session is active , else re-login and re-fetch the cookie.
      For the second part , I will probably fetch some table and see if not in appropriate format do Part 1 : Fetch Cookie - again.
      Any better way , tips would be appreciated.
       
      Thanks
       
×
×
  • Create New...