Jump to content

Recommended Posts

Posted

@ThomasBennett I would have written the loop like this --

While True
        $nResult = _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='popups-loading']//div[contains(text(),'Loading...')]")
        
        If $nResult = 1 And @error = $_WD_ERROR_Timeout Then
            ExitLoop
        EndIf
WEnd

Obviously, this doesn't handle any other type of error that may occur and I didn't set @error like you did.

Yes, you could use _WD_ExecuteScript to retrieve the text, but a more traditional method would be like this --

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//thead[@class='tableHeader-processed']//div[@class='collection-paging-info']")

; Either of the following should work
$sValue1 = _WD_ElementAction($sSession, $sElement, 'property', 'value')
$sValue2 = _WD_ElementAction($sSession, $sElement, 'value')

 

Posted

@Danp2, thank you for the optimized code!

I made a few modifications:

;Loading...
    While True
        $nResult = _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='popups-loading']//div[contains(text(),'Loading...')]")
        ;MsgBox($MB_SYSTEMMODAL, "nResult Value", $nResult, 1)
        If $nResult = 0 Or @error = $_WD_ERROR_Timeout Then
            ;MsgBox($MB_SYSTEMMODAL, "nResult Value", $nResult, 5)
            ExitLoop
        EndIf
    WEnd

I made a few modifications:

; Taught how to do the below code:
    ; https://www.autoitscript.com/forum/topic/191990-webdriver-udf-w3c-compliant-version-04282021/page/50/#comments

    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//thead[@class='tableHeader-processed']//div[@class='collection-paging-info']")
    $sValue1 = _WD_ElementAction($sSession, $sElement, 'property', 'innerText')
    ;MsgBox($MB_SYSTEMMODAL, "sValue1", $sValue1, 5)

    $aLine2 = StringSplit($sValue1, ' ', 1)

    MsgBox($MB_SYSTEMMODAL, "", $aLine2[0], 5) ; Total number of cells in the array.
    MsgBox($MB_SYSTEMMODAL, "", $aLine2[1], 5) ; First Number
    MsgBox($MB_SYSTEMMODAL, "", $aLine2[2], 5) ; of
    MsgBox($MB_SYSTEMMODAL, "", $aLine2[3], 5) ; Second Number

    $a = $aLine2[1]
    $b = $aLine2[3]

    MsgBox($MB_SYSTEMMODAL, "", $a, 5)
    MsgBox($MB_SYSTEMMODAL, "", $b, 5)


    If $b <= 32 Then
        While True
            If $a == $b Then
                ExitLoop
            EndIf
            WinActivate ("Schoology - Google Chrome")
            Send("{PGDN}")
            Sleep(2000)
            _WD_LoadWait($sSession, 2000)
            $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//thead[@class='tableHeader-processed']//div[@class='collection-paging-info']")
            $sValue1 = _WD_ElementAction($sSession, $sElement, 'property', 'innerText')
            $sLine2 = StringSplit($sValue1, ' ', 1)
            $a = $sLine2[1]
            $b = $sLine2[3]
        WEnd
    EndIf

Both are working correctly and everything is running much faster now. Thank you again!

Working on a few other things but going to call it a night for now. 

Thank you again for your time and consideration,




Thomas

Posted

Good morning @Danp2,

If $nResult = 0 Or @error = $_WD_ERROR_Timeout Then

Please do not take what I am about to say as an attack or anything personal; this is only me explaining my logic at my level of understanding.

There will be flaws in my logic and explanation. 🤓

With some limited testing I found that when the "Loading..." popup window goes away $nResult flips to 0; but I was still in the WhileLoop because the @error never seemed to = $_WD_ERROR_Timeout. So I figured the "AND" was the problem and flipped it to "OR". I was thinking about dropping the @error part altogether but figured it wouldn't hurt to have in place. 

Please tell me if my logic is flawed and thank you again for your time and consideration on this. Now back to figuring out why the laptop can't find the numbers on the screen but the desktop can find the numbers on the screen and the script works correctly on the desktop. Both are running the same version of Google Chrome: Version 90.0.4430.93 (Official Build) (64-bit). Both are Windows 10 x64. 

Thank you again and again, 




Thomas

Posted

@Danp2 past experience; so I tend to lead with apologies early in case of hurt feelings and text can cause confusion. 😇

It was late last night when I did this so I probably did it wrong. I outputted @error to a msgbox and would only receive a "7" as the output. I was expecting the see something like: "$_WD_ERROR_Timeout". 

Using the msgbox to show the value of $nResult is what taught me the flip from 1 to 0.

What's the best method to output the @error information?

Thank you




Thomas

Posted

 

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(text(),'2018')]")

I want to use variables instead of strings in XPath. How do I do that?I didn't get it right

"//a[contains(text(),$year)]"

Posted (edited)

@lhlpds try this following example:

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[contains(text(''),'" & $year & "')]")

 

btw.
:welcome:to logo_autoit_210x72.svg forum.

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Posted

_WD_GetShadowRoot will retrieve the shadow root of a web component, which can then be used to access the components internal elements. Lots of info available online if you want to research further about shadow roots.

P.S. Since this was only recently added to the W3C specs, you may run into issues trying to use this feature.

Posted
Func SetupGecko()
    _WD_Option('Driver', 'geckodriver.exe')
    _WD_Option('DriverParams', '--binary "C:\Program Files\Mozilla Firefox\firefox.exe" --log trace')
    _WD_Option('Port', 4444)

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}'

EndFunc   ;==>SetupGecko

How do Firefox logs redirect output to a file? 

I can't find an example like Chrome in the wd_demo.au3

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

Posted

I have been trying to run wd_demo.au3 with little success – "Chrome does not start and the DOS window for chromedriver does not get displayed" describes my problem exactly.

So I added the line:
    _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\Include\chromedriver.exe")
to wd_demo.au3 immediately after the 6 #include lines but it made no discernible difference (to me anyway!)

When I run chromedriver.exe manually, the DOS box reads:
    Starting ChromeDriver 90.0.4430.24 (4c6d850f087da467d926e8eddb76550aed655991-refs/branch-heads/4430@{#429}) on port 9515
    Only local connections are allowed.
    Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe.
    ChromeDriver was started successfully.
I can close the DOS box but it does not accept any other input.

After running wd_demo, AutoIt's status window reads:
    >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Program Files (x86)\AutoIt3\Include\wd_demo.au3" /UserParams    
    +>23:30:56 Starting AutoIt3Wrapper (19.1127.1402.0} from:SciTE.exe (4.2.0.0)  Keyboard:00000809  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0809)  CodePage:0  utf8.auto.check:4
    +>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\Robert Ellsmore\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Robert Ellsmore\AppData\Local\AutoIt v3\SciTE 
    >Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Program Files (x86)\AutoIt3\Include\wd_demo.au3
    +>23:30:56 AU3Check ended.rc:0
    >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Program Files (x86)\AutoIt3\Include\wd_demo.au3"    
    +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
    _WD_IsLatestRelease: True
    _WD_IsLatestRelease ==> Success
    _WD_Startup: OS:    WIN_10 WIN32_NT 19041 
    _WD_Startup: AutoIt:    3.3.14.5
    _WD_Startup: WD.au3:    0.4.0.3 (Up to date)
    _WD_Startup: WinHTTP:    1.6.4.2
    _WD_Startup: Driver:    chromedriver.exe
    _WD_Startup: Params:    --verbose --log-path="C:\Program Files (x86)\AutoIt3\Include\chrome.log"
    _WD_Startup: Port:    9515
    __WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}
    __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
    __WD_Delete: URL=HTTP://127.0.0.1:9515/session/
    __WD_Delete: StatusCode=0; ResponseText=WinHTTP request timed out before Webdriver...
    __WD_Delete ==> Webdriver Exception: WinHTTP request timed out before Webdriver
    _WD_DeleteSession: WinHTTP request timed out before Webdriver
    _WD_DeleteSession ==> Webdriver Exception: HTTP status = 0
    +>23:31:16 AutoIt3.exe ended.rc:0
    +>23:31:16 AutoIt3Wrapper Finished.
    >Exit code: 0    Time: 21.01

The log file, C:\Program Files (x86)\AutoIt3\Include\chrome.log has not been created.

I have installed Json.au3 (2018.12.29) in  C:\Program Files (x86)\AutoIt3\Include

The Chrome executable is located in C:\Program Files (x86)\Google\Chrome\Application

I know I must be missing something but I can't see what. Can you tell me where I'm going wrong.
 

Posted (edited)
1 hour ago, RDE said:

 _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\Include\chromedriver.exe")

Move this down to the SetupChrome function (replacing the existing line) and that should solve your issue.

Edit: I would have expected to see the following error in the console --

_WD_Startup ==> General Error: Error launching web driver!

 

Edited by Danp2
Posted
On 5/9/2021 at 8:13 PM, Danp2 said:

Move this down to the SetupChrome function (replacing the existing line) and that should solve your issue.

Edit: I would have expected to see the following error in the console --

_WD_Startup ==> General Error: Error launching web driver!

 

I edited wd_demo.au3 thus:

Func SetupChrome()
    _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\Include\chromedriver.exe")
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"')

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}'
EndFunc   ;==>SetupChrome
 

but no luck I'm afraid. I get an extremely brief flash of a window but that's all. chrome.log doesn't appear in the script directory nor do any downloaded files. The AutoIt output follows:

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Program Files (x86)\AutoIt3\Include\wd_demo.au3" /UserParams    
+>23:44:11 Starting AutoIt3Wrapper (19.1127.1402.0} from:SciTE.exe (4.2.0.0)  Keyboard:00000809  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0809)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\Robert Ellsmore\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\Robert Ellsmore\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Program Files (x86)\AutoIt3\Include\wd_demo.au3
+>23:44:12 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Program Files (x86)\AutoIt3\Include\wd_demo.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
_WD_IsLatestRelease: True
_WD_IsLatestRelease ==> Success
_WD_Startup: OS:    WIN_10 WIN32_NT 19041 
_WD_Startup: AutoIt:    3.3.14.5
_WD_Startup: WD.au3:    0.4.0.3 (Up to date)
_WD_Startup: WinHTTP:    1.6.4.2
_WD_Startup: Driver:    C:\Program Files (x86)\AutoIt3\Include\chromedriver.exe
_WD_Startup: Params:    --verbose --log-path="C:\Program Files (x86)\AutoIt3\Include\chrome.log"
_WD_Startup: Port:    9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "excludeSwitches": [ "enable-automation"], "useAutomationExtension": false }}}}
__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
__WD_Delete: URL=HTTP://127.0.0.1:9515/session/
__WD_Delete: StatusCode=0; ResponseText=WinHTTP request timed out before Webdriver...
__WD_Delete ==> Webdriver Exception: WinHTTP request timed out before Webdriver
_WD_DeleteSession: WinHTTP request timed out before Webdriver
_WD_DeleteSession ==> Webdriver Exception: HTTP status = 0
+>23:45:38 AutoIt3.exe ended.rc:0
+>23:45:38 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 86.75

On 5/9/2021 at 8:13 PM, Danp2 said:

 

 

Posted
14 hours ago, Danp2 said:

@RDE I suspect that you may be encountering a rights issue. Try moving the script, the chromedriver executable and your log file to the another directory, preferable not beneath C:\Program Files (x86).

Many thanks for your swift reply. I copied everything to to my D: drive and ran it from there. This worked but threw up another problem.

The browser now opens up properly but then immediately opens two tabs with consent forms in respect of cookies and data, one from Google and one from Yahoo. Even after these have been filled in, nothing else happens except that chrome.log is created, no downloads etc.

I note that line #31 of chrome.log reads: "skip_first_run_ui": true. Is that line intended to stop this happening? Is it something to do with Europe's GDPR rules? I've attached chrome.log in the hope that it can help.

chrome.log

Posted

The UDF is really good. 


But I’m looking  for a function to get the Id of  a element.
I find the element by XPath, but I can’t found a function to get the id of this element.

I can’t believe, I think I not to see the forest for the trees. 
Can somebody give me a tip with that.

 

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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