Jump to content

Get URL or TAB Name for a variable


Recommended Posts

Hello guys, i know autoit since 4 days and i have several problems i solved with this forum search function.

Now i have some trouble with getting my currently URL or currently TAB Name for a variable.

 

Background: I have an upload process on a website. If internet connection is lost or something went wrong (website is not loading, buttons are not on the right location) autoit makes weird things like clicking around without sense.

To avoid that, i want to exit the script if something go wrong. The upload process is going over 4 urls (start site/ copy existing/uploading image/ entering information)

If i can read URL or TAB Name i have $variable= www.example.com/

With this i can use a IF $variable contains "example" or is www.example.com THEN continue script ELSE exit()

 

I tried these scripts to:

#1 read URL (do not work sometimes) 

https://www.autoitscript.com/forum/topic/182674-web-browser-url-checker/

OR

#2 read TAB names (give me constantly the Name of ALL tabs in one variable, also do not end in the loop, so script do not continue!!) 

https://www.autoitscript.com/forum/topic/201151-ui-automation-getting-tab-names/

 

MY QUESTION so how can i end the loop, my script do not continue after this code (link #2) and How i get only the TAB name of the used Tab? I do not want this array sh't

#include "CUIAutomation2.au3"

  ; Window handle
  Local $hWindow = WinGetHandle( "[CLASS:Chrome_WidgetWin_1]" )
  If Not IsHWnd( $hWindow ) Then Return ConsoleWrite( "$hWindow ERR" & @CRLF )
  ConsoleWrite( "$hWindow OK" & @CRLF )

  ; Activate window
  WinActivate( $hWindow )
  Sleep( 100 )

  ; UI Automation object
  Local $oUIAutomation = ObjCreateInterface( $sCLSID_CUIAutomation, $sIID_IUIAutomation, $dtagIUIAutomation )
  If Not IsObj( $oUIAutomation ) Then Return ConsoleWrite( "$oUIAutomation ERR" & @CRLF )
  ConsoleWrite( "$oUIAutomation OK" & @CRLF )

  ; Desktop element
  Local $pDesktop, $oDesktop
  $oUIAutomation.GetRootElement( $pDesktop )
  $oDesktop = ObjCreateInterface( $pDesktop, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oDesktop ) Then Return ConsoleWrite( "$oDesktop ERR" & @CRLF )
  ConsoleWrite( "$oDesktop OK" & @CRLF )

  ; Chrome window
  Local $pCondition
  $oUIAutomation.CreatePropertyCondition( $UIA_ClassNamePropertyId, "Chrome_WidgetWin_1", $pCondition )
  If Not $pCondition Then Return ConsoleWrite( "$pCondition ERR" & @CRLF )
  ConsoleWrite( "$pCondition OK" & @CRLF )

  Local $pChrome, $oChrome
  $oDesktop.FindFirst( $TreeScope_Descendants, $pCondition, $pChrome )
  $oChrome = ObjCreateInterface( $pChrome, $sIID_IUIAutomationElement, $dtagIUIAutomationElement )
  If Not IsObj( $oChrome ) Then Return ConsoleWrite( "$oChrome ERR" & @CRLF )
  ConsoleWrite( "$oChrome OK" & @CRLF )


  ; Tab item
  Local $pCondition1
  $oUIAutomation.CreatePropertyCondition( $UIA_ControlTypePropertyId, $UIA_TabItemControlTypeId, $pCondition1 )
  If Not $pCondition1 Then Return ConsoleWrite( "$pCondition1 ERR" & @CRLF )
  ConsoleWrite( "$pCondition1 OK" & @CRLF )


;~   Find All tab items
  Local $pTabs, $oUIElementArray, $iElements, $pFound, $oFound, $value
  $oChrome.FindAll( $TreeScope_Descendants, $pCondition1, $pTabs )
  $oUIElementArray = ObjCreateInterface($pTabs, $sIID_IUIAutomationElementArray, $dtagIUIAutomationElementArray)
  $oUIElementArray.Length( $iElements )
  ConsoleWrite( "$iElements:" & $iElements & @CRLF )
  For $i = 0 To $iElements - 1 
        Local $pFound
        $oUIElementArray.GetElement($i, $pFound)
        ConsoleWrite($pFound & @CRLF)
        $pFound.GetCurrentPropertyValue($UIA_NamePropertyId,$value) ;<==PROBLEM HERE
        ConsoleWrite($value & @CRLF)
  Next

 

Edited by JD943
Link to comment
Share on other sites

This is a quick and dirty way of getting a browser link.

Sleep(3000)
$WTitle = WinGetTitle('[ACTIVE]')
Send('{F6}')
Sleep(100)
Send('{APPSKEY}')
Sleep(100)
Send('c')
Sleep(100)
Send('{F6}')
$Link = ClipGet()
ToolTip($Link, 0, 0, 'Link', 1)

When messing with functions that require the internet, i'm a much bigger fan of using the ie functions that are present in autoit already.

If you want to leave the loop, place a condition, and then exitloop when the condition is met.

Hope this helps.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

@careca thank you, that works!

 

do you have also a way to repeat the loop in this position when internet connection get lost. Something with loop count.

 

I mean: For = 1 to 50

internetconnection get lost OR Tab name os wrong on the 43 time

loop will repeat 43 and go til 50.

 

so i can search for a while function to read internet connection and then do repeat the loop if internet connection got lost and also if $Wtitle = do not contain the right TAB Name.

all topics i found were 5-8 years old.

Link to comment
Share on other sites

There are many ways to check for internet connection, one is to ping a website. There are many topics about it.

As far as loops go, you're on track, it's just a matter of deciding on the way you want to check for internet connection and integrate it into the code.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

MsgBox ( 64,"",InetCheck())

Func InetCheck()
Ping ("autoitscript.com", 250)
If Not @error Then
    Return SetError ( 0,0,"connection avaiable (first attempt)" )
Else
    Ping ("google.com", 250)
If Not @error Then
    Return SetError ( 0,0,"connection avaiable (second attempt)" )
Else
    Ping ("facebook.com", 250)
If Not @error Then
    Return SetError ( 0,0,"connection avaiable (third attempt)" )
Else
 Return SetError ( -1,0,"no connection" )
EndIf
EndIf
EndIf
EndFunc

e.g. this

you could change the SetError to True and False to work with it

why do i get garbage when i buy garbage bags? <_<

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...