Jump to content

Search for a word on a website (Browser Edge)


Recommended Posts

Hello,

I am trying with WebDriver UDF to search for a text (in this example I am looking for: Available) in the browser Edge.

And afterwards it should tell me if the script found the text or not.

However I am getting the error below:

C:\Program Files (x86)\AutoIt3\Include\wd_core.au3 (832) : ==> Unterminated string.: 
<!-- '"` --><!-- </textarea></xmp> --></option></form><form id="query-builder-test-form" action="" accept-charset="UTF-8" method="get">
#include "wd_core.au3"
#include "wd_helper.au3"

; Start WebDriver for Microsoft Edge
Local $sDesiredCapabilities, $sURL = "https://test.com"
_WD_Startup()

; Set the path to the Edge WebDriver (replace with your actual path)
_WD_SetDriver("C:\path\to\msedgedriver.exe")

; Main loop to check every 1 minute
While 1
    ; Try-Catch for safer execution
    Local $sSession = ""
    Local $pageSource = ""
    Local $bError = False

    ; Open a new session for Edge
    $sSession = _WD_CreateSession($sDesiredCapabilities)

    If @error Then
        ConsoleWrite("Error creating WebDriver session." & @CRLF)
        $bError = True
    EndIf

    ; Navigate to the specified URL if no errors
    If Not $bError Then
        _WD_Navigate($sSession, $sURL)
        Sleep(3000) ; Give the page some time to load
    EndIf

    ; Try to get the page source
    If Not $bError Then
        $pageSource = _WD_ElementAction($sSession, "source", "get", "")
        If $pageSource = "" Or @error Then
            ConsoleWrite("Error getting page source." & @CRLF)
            $bError = True
        EndIf
    EndIf

    ; Check if "Available" is present in the page source
    If Not $bError Then
        If StringInStr($pageSource, "Available") Then
            MsgBox(0, "Status", "Available OK")
        Else
            MsgBox(0, "Status", "Available not found!")
        EndIf
    EndIf

    ; Close session and cleanup if session was created
    If Not $bError Then
        _WD_DeleteSession($sSession)
    EndIf

    ; Wait for 1 minute before checking again
    Sleep(60000)
WEnd

; Shutdown WebDriver after loop ends (if ever)
_WD_Shutdown()

 

Any idea what I am doing wrong?
 

Edited by hendrikhe
Link to comment
Share on other sites

Hi,

We won't be able to run the code as posted because you are using functions that don't exist in the Webdriver UDF (_WD_SetDriver for example).

Also, your usage of _WD_ElementAction isn't correctly. You should check out_WD_GetSource in the help file.

Regards, Dan

P.S. If you've modified the files that were shipped with the WD UDF, then you may want to rethink your plans so that you don't have to redo everything when a new update is released.

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...