Jump to content

Need help with WebDriver


Recommended Posts

Hey everyone,

I'm trying to get WebDriver up and running, but I’m having trouble getting my custom script to start. Here’s the script I’m using:

Spoiler
#include "wd_helper.au3"
#include "wd_capabilities.au3"

_Example()




Func _Example()
    # REMARK
    #   This is not functional script
    #   It only shows the concept how to use WebDriver UDF

    #Region ; initialize webdriver sesion

;~  ; you should take care about download/update dirver
;~  If $IDYES = MsgBox($MB_YESNO + $MB_TOPMOST + $MB_ICONQUESTION + $MB_DEFBUTTON1, "Question", _
;~          "Do you want to download/update driver ?") Then
;~      _WD_UpdateDriver('chrome')
;~  EndIf

    ; specify driver, port and other options
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"')

    ; start the driver
    _WD_Startup()
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; create capabilites for session
    _WD_CapabilitiesStartup()
    _WD_CapabilitiesAdd('alwaysMatch', 'chrome')
    _WD_CapabilitiesAdd('w3c', True)
    _WD_CapabilitiesAdd('excludeSwitches', 'enable-automation')
    Local $sCapabilities = _WD_CapabilitiesGet()

    ; create session with given Capabilities
    Local $WD_SESSION = _WD_CreateSession($sCapabilities)
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    #EndRegion ; initialize webdriver sesion

    #Region ; do your's stuff


    Global Const $sURL =    "URL"
    Global Const $mail =    "MAIL"
    Global Const $pw =      "PW1"
    Global Const $pin =     "PW2"


    ; navigate to some website
    _WD_Navigate($WD_SESSION, $sURL)
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; wait for loading process ends
    _WD_LoadWait($WD_SESSION, 1000)
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; find element
    Local $sXPath = '//*[@id="Enter user name"]'
    Local $sElement = _WD_FindElement($WD_SESSION, $_WD_LOCATOR_ByXPath, $sXPath)
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; set element
    _WD_SetElementValue($WD_SESSION, $sElement, $mail)
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's


    #EndRegion ; do your's stuff

    #Region ; Clean Up

    ; on the end session should be deleted
    _WD_DeleteSession($WD_SESSION)
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    ; and driver should be closed
    _WD_Shutdown()
    If @error Then Return SetError(@error, @extended, 0) ; always remember to check and handle error's

    #EndRegion ; Clean Up

EndFunc   ;==>_Example

 

 

The strange thing is that when I run the demo script, it works just fine. But with this script, nothing happens at all—no browser window opens, and there are no errors.

image.png.ab8179d59d0e91ec227a5ea8a4c49ee8.png

 

Any advice on what might be going wrong or how I can troubleshoot this?

Thanks in advance for any help!

 

PS:

This is the demo:

Spoiler

image.thumb.png.d2c21cc2b3dec042deb58c6e584107e2.png

Here its running.

 

Edited by Jotos
Link to comment
Share on other sites

Hi @Jotos 👋 ,

change this

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

to this

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

and try again.

Explanation:

Best regards
Sven

Edited by SOLVE-SMART

Stay innovative!

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

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