Jump to content

Array is not matching with the second array


Recommended Posts

I have an html table that displays data along with an excel spreadsheet that has the same data as the html table. I am wanting to only match the Title column in my html table with the Title column in my Excel spreadsheet. If the titles match, click on the Edit hyperlink and continue to loop to next row. The issue I'm experience is its not matching correctly. So far  i've written the codes below:

<table border="1" class="test">
    
    <tr>
        
        <th> UniqueID</th>
        <th> Title</th>
        <th> UserID</th>
        <th> Address</th>
        <th> Gender </th>
    </tr>
    
    <tr>
        
        <td> 1 </td>
        <td> Title1 </td>
        <td> 12345 </td>
        <td> Manila </td>
        <td>
            
            <span> Male </span>
            
        </td>
    </tr>
    <tr>
        
        <td align="center" colspan="5">
           <a href="#" class="testlink">Edit</a>
        </td>
    </tr>
    <tr>
        
        <td> 2 </td>
        <td> Title2 </td>
        <td> 67891 </td>
        <td> Valenzuela </td>
        <td>
            
            <span> Female </span>
            
        </td>
    </tr>
    <tr>
        
        <td align="center" colspan="5" >
           <a href="#" class="testlink">Edit</a>
        </td>
    </tr>
    <tr>
        
        <td> 3 </td>
        <td> Title3 </td>
        <td> 88888 </td>
        <td> Ohio </td>
        <td>
            
            <span> Male </span>
            
        </td>
    </tr>
    <tr>
        
        <td align="center" colspan="5" >
           <a href="#" class="testlink">Edit</a>
        </td>
    </tr>
    <tr>
        
        <td> 4 </td>
        <td> Title4 </td>
        <td> 77777 </td>
        <td> California </td>
        <td>
            
            <span> Female </span>
            
        </td>
    </tr>
    <tr>
        
        <td align="center" colspan="5" >
           <a href="#" class="testlink">Edit</a>
        </td>
    </tr>
    <tr>
        
        <td> 5 </td>
        <td> Title5 </td>
        <td> 33333 </td>
        <td> Arizona </td>
        <td>
            
            <span> Male </span>
            
        </td>
    </tr>
    <tr>
        
        <td align="center" colspan="5" >
           <a href="#" class="testlink">Edit</a>
        </td>
    </tr>
    
</table>
#Include "Chrome.au3"

#Include "wd_core.au3"

#Include "wd_helper.au3"

#Include "Excel.au3"

#Include "_HtmlTable2Array.au3" 

#Include "Array.au3"  

Local $sDesiredCapabilities, $sSession

SetupChrome()

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_LoadWait($sSession)

_WD_Navigate($sSession, "index.html")

Sleep(6000)

Local $oExcel = _Excel_Open()

Local $oWorkbook = _Excel_BookOpen($oExcel, "test.xlsx")

; Get the table element
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='test']")

; Retrieve HTML
$sHTML = _WD_ElementAction($sSession, $sElement, "Property", "outerHTML")

;Local $aTable = _HtmlTableGetWriteToArray($sHTML)

Local $aArray1 = _Excel_RangeRead($oWorkbook,1,$oWorkbook.ActiveSheet.Usedrange.Columns("B:B"))
Local $aArray2 = _HtmlTableGetWriteToArray($sHTML)

;_ArrayDisplay($aArray1)
;_ArrayDisplay($aArray2)

For $i = UBound($aArray1) - 1 To 0 step - 1
    For $j = UBound($aArray2) - 1 to 0 step - 1
        If  $aArray1[$i][1] == $aArray2[$j][1] Then
            _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@class,'testlink') or contains(text(),'Edit')]")
            $test1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@class,'testlink') or contains(text(),'Edit')]")
            _WD_ElementAction($sSession, $test1, 'click')
            ;_ArrayDisplay($aArray1)
           ;_ArrayDelete($aArray1 , $i)
           ;exitloop
        EndIf
    Next
Next

_WD_Shutdown()

 

Func SetupChrome()

    _WD_Option('Driver', 'chromedriver.exe')

    _WD_Option('Port', 9515)

    _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}'

EndFunc   ;==>SetupChrome

Would appreciate if anyone can provide tips, or point me in the right direction in doing it.

 

test.xlsx

Edited by Hermes
Link to post
Share on other sites

I think the problem is that double loops.  It should be a single comparing the same indice of each of the arrays.  I am supposing that both arrays have always the same dimension (in your example it is 5).  Also your loop should not be in inverse way.  And your find element should use the previous found element.

 

Link to post
Share on other sites

@NineThanks for responding! I modified the script and removed the extra for loop:

#Include "Chrome.au3"

#Include "wd_core.au3"

#Include "wd_helper.au3"

#Include "Excel.au3"

#Include "_HtmlTable2Array.au3" 

#Include "Array.au3"  

Local $sDesiredCapabilities, $sSession

SetupChrome()

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_LoadWait($sSession)

_WD_Navigate($sSession, "index.html")

Sleep(6000)

Local $oExcel = _Excel_Open()

Local $oWorkbook = _Excel_BookOpen($oExcel, "test.xlsx")

; Get the table element
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='test']")

; Retrieve HTML
$sHTML = _WD_ElementAction($sSession, $sElement, "Property", "outerHTML")

;Local $aTable = _HtmlTableGetWriteToArray($sHTML)

Local $aArray1 = _Excel_RangeRead($oWorkbook,1,$oWorkbook.ActiveSheet.Usedrange.Columns("B:B"))
Local $aArray2 = _HtmlTableGetWriteToArray($sHTML)

;_ArrayDisplay($aArray1)
;_ArrayDisplay($aArray2)

For $i = 0 To UBound($aArray1) - 1
        If  $aArray1[$i][1] == $aArray2[$i][1] Then
            _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@class,'options-list-item') or contains(text(),'Edit')]")
            $test1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@class,'options-list-item') or contains(text(),'Edit')]")
            _WD_ElementAction($sSession, $test1, 'click')
            ;_ArrayDisplay($aArray1)
           ;_ArrayDelete($aArray1 , $i)
           ;exitloop
        EndIf
Next 

_WD_Shutdown()

 

Func SetupChrome()

    _WD_Option('Driver', 'chromedriver.exe')

    _WD_Option('Port', 9515)

    _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}'

EndFunc   ;==>SetupChrome

And now i'm getting this error message:

==> Array variable has incorrect number of subscripts or subscript dimension range exceeded

When you say "And your find element should use the previous found element.", not really sure what you mean by that.

Link to post
Share on other sites

You should read your excel sheet starting at row 2 since you have a title.

Look at _WD_FindElement there is a starting element (4th parameter), I think you will need it...

Link to post
Share on other sites

Hi @Nine I updated code below:

#Include "Chrome.au3"

#Include "wd_core.au3"

#Include "wd_helper.au3"

#Include "Excel.au3"

#Include "_HtmlTable2Array.au3" 

#Include "Array.au3"  

Local $sDesiredCapabilities, $sSession

SetupChrome()

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_LoadWait($sSession)

_WD_Navigate($sSession, "index.html")

Sleep(6000)

Local $oExcel = _Excel_Open()

Local $oWorkbook = _Excel_BookOpen($oExcel, "test.xlsx")

; Get the table element
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='test']")

; Retrieve HTML
$sHTML = _WD_ElementAction($sSession, $sElement, "Property", "outerHTML")

;Local $aTable = _HtmlTableGetWriteToArray($sHTML)

Local $aArray1 = _Excel_RangeRead($oWorkbook,1,$oWorkbook.ActiveSheet.Usedrange.Columns("B:B"))
Local $aArray2 = _HtmlTableGetWriteToArray($sHTML)

;_ArrayDisplay($aArray1)
;_ArrayDisplay($aArray2)

Global $Skipline = 0 ;0==> first line

Local $temprf

For $i = 0 To UBound($aArray1, $aArray2) - 1
   If $Skipline = $i Then ContinueLoop

       $temprf &= $aArray1[$i]
        If  $aArray1[$i] == $aArray2[$i] Then
            _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(@class,'options-list-item') or contains(text(),'Edit')]")
            $test1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "//a[contains(@class,'options-list-item') or contains(text(),'Edit')]", $aArray1[$i])
            _WD_ElementAction($sSession, $test1, 'click')
            ;_ArrayDisplay($aArray1)
           ;_ArrayDelete($aArray1 , $i)
           ;exitloop
        EndIf
Next 

_WD_Shutdown()

 

Func SetupChrome()

    _WD_Option('Driver', 'chromedriver.exe')

    _WD_Option('Port', 9515)

    _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}'

EndFunc   ;==>SetupChrome

I managed to skipped the first row, but it doesn't click the element (edit) link.

Link to post
Share on other sites

Here what your code could be if I understand you correctly :

#Include "wd_core.au3"
#Include "wd_helper.au3"
#Include <Excel.au3>
#Include <Array.au3>

Local $sDesiredCapabilities = SetupChrome()
_WD_Startup()
Local $sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "file://C:\\Applications\\AutoIt\\WebDriver\\HTML Examples\\Table.html")
_WD_LoadWait($sSession)

Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='test']")
ConsoleWrite ("Table " & $sElement & @CRLF)
Local $aArray1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[contains(.,'Title')]", $sElement, True)
For $i = 0 to UBound($aArray1) - 1
  $aArray1[$i] = _WD_ElementAction($sSession, $aArray1[$i], 'text')
Next
_ArrayDisplay($aArray1)
Local $aElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[@class='testlink']", $sElement, True)
_ArrayDisplay($aElement)

Local $oExcel = _Excel_Open()
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\test.xlsx")
Local $aArray2 = _Excel_RangeRead($oWorkbook, Default,"B2:B6")
_Excel_Close($oExcel)
_ArrayDisplay($aArray2)

; search from Excel array cells into Chrome table
Local $iIdx
For $i = 0 To UBound($aArray2) - 1
  $iIdx = _ArraySearch($aArray1, $aArray2[$i])
  If @error Then ContinueLoop
  ConsoleWrite ("Found at " & $iIdx & @CRLF)
  _WD_ElementAction($sSession, $aElement[$iIdx], 'click')
Next

;_WD_DeleteSession($sSession)
;_WD_Shutdown()

Local $aDir = _FileListToArrayRec(@TempDir, "scoped_dir*;chrome_*", $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH)
Sleep(2000)
For $i = 1 To $aDir[0]
  DirRemove($aDir[$i], $DIR_REMOVE)
Next

Func SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')
    Return '{"capabilities":{"alwaysMatch":{"goog:chromeOptions":{"w3c":true,' & _
    '"excludeSwitches":["enable-automation"],"useAutomationExtension":false}}}}'
EndFunc   ;==>SetupChrome

 

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 Danp2
      Introduction
      This UDF will allow you to interact with any browser that supports the W3C WebDriver specifications. Supporting multiple browsers via the same code base is now possible with just a few configuration settings.
      Requirements
      JSON UDF https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn
      WinHTTP UDF https://www.autoitscript.com/forum/topic/84133-winhttp-functions/
      HtmlTable2Array UDF (optional) https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/
      WebDriver for desired browser
      Chrome WebDriver https://sites.google.com/a/chromium.org/chromedriver/downloads FireFox WebDriver https://github.com/mozilla/geckodriver/releases Edge WebDriver https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      See the wiki for details on the UDF --
      https://www.autoitscript.com/wiki/WebDriver
      Please post any questions, suggestions or errors in the GH&S thread.
      https://www.autoitscript.com/forum/topic/205553-webdriver-udf-help-support-iii/
      Previous support threads (Closed)
      https://www.autoitscript.com/forum/topic/192730-webdriver-udf-help-support/
      https://www.autoitscript.com/forum/topic/201106-webdriver-udf-help-support-ii/
       
    • By Hermes
      I have Index.html where it contains a frame with a source "frame1.html". I can select/highlight elements in index.html but unable to select/highlight elements inside the frame with the src "frame1.html", the autoit output is throwing error:
      __WD_Post: URL=HTTP://127.0.0.1:9515/session/2143396006437be4005db3b84acc1496/element/8be1c3c4-5bb1-42b1-8cde-7954765cbc61/element; $sData={"using":"css selector","value":"frameset:nth-of-type(1)"} __WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\... __WD_Post ==> No match: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"css selector\",\"selector\":\"frameset:nth-of-type(1)\"}\n (Session info: chrome=90.0.4430.212)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00FCE7D3+124883]\n\tOrdinal0 [0x00FCE7B1+124849]\n\tGetHandleVerifier [0x01218688+193832]\n\tGetHandleVerifier [0x0123C478+340760]\n\tGetHandleVerifier [0x012361F1+315537]\n\tGetHandleVerifier [0x012516BA+427354]\n\tGetHandleVerifier [0x01236176+315414]\n\tGetHandleVerifier [0x0125174A+427498]\n\tGetHandleVerifier [0x0125D6EB+476555]\n\tGetHandleVerifier [0x0125154B+426987]\n\tGetHandleVerifier [0x01234FFD+310941]\n\tGetHandleVerifier [0x01235D8E+314414]\n\tGetHandleVerifier [0x01235D19+314297]\n\tGetHandleVerifier [0x012F31EC+1089676]\n\tGetHandleVerifier [0x012F17C9+1082985]\n\tGetHandleVerifier [0x012F13A3+1081923]\n\tGetHandleVerifier [0x013ED9FD+2115741]\n\tOrdinal0 [0x0111B82E+1488942]\n\tOrdinal0 [0x010B5A7D+1071741]\n\tOrdinal0 [0x010B559B+1070491]\n\tOrdinal0 [0x010B54B1+1070257]\n\tOrdinal0 [0x010EFF53+1310547]\n\tBaseThreadInitThunk [0x770662C4+36]\n\tRtlSubscribeWnfStateChangeNotification [0x776B1B69+1081]\n\tRtlSubscribeWnfStateChangeNotification [0x776B1B34+1028]\n"}} Auto IT Script:
      #Include "wd_core.au3" #Include "wd_helper.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, 'index.html') _WD_LoadWait($sSession) Local $index = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)") Local $index1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)", $index) Local $index2 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frame:nth-of-type(1)", $index1) Local $index3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "frameset:nth-of-type(1)", $index2) _WD_HighlightElement($sSession, $index2, 1) _WD_HighlightElement($sSession, $index3, 1) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome  

      frame1.html index.html
    • By Hermes
      Hi, sometimes when I run my script in GUI (SciTe Editor) or as an executable file, the chrome driver launches but the chrome browser does not but when I re-run the script again - chrome driver launches and so does the browser. Here is the error that I'm getting:
      __WD_Post: StatusCode=0; ResponseText=WinHTTP request timed out before Webdriver... __WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver _WD_CreateSession: WinHTTP request timed out before Webdriver _WD_CreateSession ==> Webdriver Exception: HTTP status = 0 Just wondering if there's a way to re-launch both the driver and browser without having to rerun the script/executable.
       
       
    • By SkysLastChance
      I am using web driver and xpaths to automate chrome. 
      I am able to edit everything I need to until I get these pop ups. Then when I try to find the xpath it act like it does not exist. 
      This code below is working to find input fields on the main page of the site. But, if I try the same thing for ones in the popover it will not find it. 😕
      $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[substring(@id, string-length(@id) - string-length('_3') + 1 ) = '_3']") _WD_ElementAction($sSession, $sElement, 'value', "TEST") Here is the html

      Any idea why it is not finding the element inside these pop overs?
       
       
      HTML:
       
    • By Hermes
      Hello, the script below will read column A from an excel file - and if a value matches in the browser, it will click the corresponding link and click on a specific button to paste the data, then writes "Completed" in Column B. It will continue to read from the excel file and do the same thing for all the remaining rows.
      #Include "Chrome.au3" #Include "wd_core.au3" #Include "wd_helper.au3" #Include "WinHttp.au3" #include <MsgBoxConstants.au3> #include <File.au3> #include <IE.au3> #include <Array.au3> #include <INet.au3> #include <AutoItConstants.au3> #include <WinAPIFiles.au3> #include <GDIPlus.au3> #include <Excel.au3> #Include "WinHttp.au3" #Include "_HtmlTable2Array.au3" Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_LoadWait($sSession) _WD_Navigate($sSession, "table1.html") _WD_LoadWait($sSession) _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//table[@class='main']") ;ConsoleWrite ("mat-table " & $sElement & @CRLF) Local $aArray1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//td[contains(@class,'data')]", $sElement, True) sleep(1000) For $i = 0 to UBound($aArray1) - 1 $aArray1[$i] = _WD_ElementAction($sSession, $aArray1[$i], 'text') Next ;_ArrayDisplay($aArray1) ;Email variables $SmtpServer = "" ; address for the smtp-server to use - REQUIRED $FromName = "Hermes" ; name from who the email was sent $FromAddress = "sender@gmail.com" ; address from where the mail should come $ToAddress = "recipient@gmail.com" ; destination address of the email - REQUIRED, use commas (,) to add more email addresses $Subject = "File not found" ; subject from the email - can be anything you want it to be $Body = "File not found!" ; the messagebody from the mail - can be left blank but then you get a blank mail $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed $CcAddress = "" ; address for cc - leave blank if not needed $BccAddress = "" ; address for bcc - leave blank if not needed $Importance = "High" ; Send message priority: "High", "Normal", "Low" $Username = "" ; username for the account used from where the mail gets sent - REQUIRED $Password = "" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS $tls = 0 ; enables/disables TLS when required Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters If FileExists($sWorkbook) Then ;Check if the file exist. Local $oAppl = _Excel_Open() Local $sWorkbook = "c:\test.xlsx" Local $oWorkbook = _Excel_BookOpen($oAppl, $sWorkbook) ;open excel and pass both parameters Local $aArray2 = _Excel_RangeRead($oWorkbook,Default,$oWorkbook.ActiveSheet.Usedrange.Columns("A:A")) Local $iIdx Local $Skipline = 0 ;0==> first line Do Local $temprf For $i = 0 To UBound($aArray2) - 1 $temprf &= $aArray2[$i] _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]") Local $aElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, ".//a[contains(@class,'edit') and contains(text(),'Edit')]", $sElement, True) $iIdx = _ArraySearch($aArray1, $aArray2[$i]) If @error Then ContinueLoop _WD_ElementAction($sSession, $aElement[$iIdx], 'click') If $i < $Skipline Then ContinueLoop $oRange = $oWorkbook.ActiveSheet.Range("B" & $i + 1 & ":XFD" & $i + 1) _Excel_RangeCopyPaste($oWorkbook.Activesheet, $oRange) ;Paste Local $oTest4 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "pastebutton") _WD_ElementAction($sSession, $oTest4, 'click') Sleep(1000) ;Save Button Local $save3 = _WD_FindElement($sSession, $_WD_LOCATOR_ByCSSSelector, "button.button") _WD_ElementAction($sSession, $save3, 'click') _Excel_RangeWrite($oWorkbook, $oWorkbook.Activesheet, "Completed", "B" & $i+1) sleep(1000) Next Until (Not @error) _Excel_Close($oWorkbook) Else _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl, $tls) Exit EndIf _WD_LoadWait($sSession) ;Attaching files to emails Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0, $tls = 0) Local $objEmail = ObjCreate("CDO.Message") $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>' $objEmail.To = $s_ToAddress Local $i_Error = 0 Local $i_Error_desciption = "" If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress $objEmail.Subject = $s_Subject If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_Body & @CRLF EndIf $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer If Number($IPPort) = 0 then $IPPort = 25 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort ;Authenticated SMTP If $s_Username <> "" Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password EndIf ; Set security params If $ssl Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True If $tls Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendtls") = True ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send $objEmail="" EndFunc ;==>_INetSmtpMailCom Local $aDir = _FileListToArrayRec(@TempDir, "scoped_dir*;chrome_*", $FLTAR_FOLDERS, $FLTAR_NORECUR, $FLTAR_NOSORT, $FLTAR_FULLPATH) Sleep(2000) For $i = 1 To $aDir[0] DirRemove($aDir[$i], $DIR_REMOVE) Next _WD_LoadWait($sSession) _WD_Shutdown() Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized","disable-infobars"]}}}}' EndFunc ;==>SetupChrome If the excel file doesn't exists in the folder, it will send an email to a specific recipient.
      What i am trying figure out now is if the excel crashes while the script/loop is running, I want to relaunch the excel file continue to the last row before the excel crashed. So if the value of column B is not marked as "completed", it should continue from that row
      Appreciate any help that I can get to achieve this.
      table1.html test.xlsx
×
×
  • Create New...