Danp2 / au3WebDriver

Web Driver UDF for AutoIt
MIT License
107 stars 21 forks source link

Error when using edge web driver in compiled script #495

Closed enthusedcoder closed 10 months ago

enthusedcoder commented 11 months ago

Bug report

Describe the bug

So, I used code that was pretty much copy/pasted from the demo example provided in the repo, which puzzles me all the more why I am encountering this issue. I have a script that I have written that uses the Microsoft Edge web driver to automate some tasks, but when the compiled script attempts to do this, the following message box appears on the screen, and the browser fails to load the web page:

image

You may have noticed that I specifically say that this issue occurs when the code is run by a compiled script. That is because, when the uncompiled script is run via scite (in scite window, "tools" > "Go" menu), the error does not occur, meaning that it is working at one point. AT least, this used to be the case, as, when I attempted to replicate the issue to post here, the message box just would not appear when it previously had, though the edge web driver still failed to launch and automate Edge. I then checked the driver's log file, which contained the following content:

[1697043034.102][INFO]: Starting Microsoft Edge WebDriver 117.0.2045.60 (a31cef5dc4c1f66dc0bb957c3250ba527e99b945) on port 9515
[1697043034.102][INFO]: Please see https://aka.ms/WebDriverSecurity for suggestions on keeping Microsoft Edge WebDriver safe.
[1697043035.478][INFO]: [091a22de55eacd9eb2ccd345a646ba74] COMMAND InitSession {
   "capabilities": {
      "alwaysMatch": {
         "ms:edgeOptions": {
            "excludeSwitches": [ "enable-automation" ]
         }
      }
   }
}
[1697043035.483][INFO]: Populating Preferences file: {
   "alternate_error_pages": {
      "enabled": false
   },
   "autofill": {
      "enabled": false
   },
   "browser": {
      "check_default_browser": false
   },
   "distribution": {
      "import_bookmarks": false,
      "import_history": false,
      "import_search_engine": false,
      "make_chrome_default_for_user": false,
      "skip_first_run_ui": true
   },
   "dns_prefetching": {
      "enabled": false
   },
   "profile": {
      "content_settings": {
         "pattern_pairs": {
            "https://*,*": {
               "media-stream": {
                  "audio": "Default",
                  "video": "Default"
               }
            }
         }
      },
      "default_content_setting_values": {
         "geolocation": 1
      },
      "default_content_settings": {
         "geolocation": 1,
         "mouselock": 1,
         "notifications": 1,
         "popups": 1,
         "ppapi-broker": 1
      },
      "password_manager_enabled": false
   },
   "safebrowsing": {
      "enabled": false
   },
   "search": {
      "suggest_enabled": false
   },
   "translate": {
      "enabled": false
   }
}
[1697043035.483][INFO]: Populating Local State file: {
   "background_mode": {
      "enabled": false
   },
   "ssl": {
      "rev_checking": {
         "enabled": false
      }
   }
}
[1697043035.486][INFO]: Launching Microsoft Edge: "C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" --allow-pre-commit-input --disable-background-networking --disable-backgrounding-occluded-windows --disable-client-side-phishing-detection --disable-default-apps --disable-hang-monitor --disable-popup-blocking --disable-prompt-on-repost --disable-sync --enable-logging --log-level=0 --no-first-run --no-service-autorun --password-store=basic --remote-debugging-port=0 --test-type=webdriver --use-mock-keychain --user-data-dir="C:\WINDOWS\SystemTemp\scoped_dir40052_1654823555" data:,
[1697043035.881][INFO]: [091a22de55eacd9eb2ccd345a646ba74] RESPONSE InitSession ERROR session not created: Microsoft Edge failed to start: exited normally.
  (session not created: DevToolsActivePort file doesn't exist)
  (The process started from msedge location C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe is no longer running, so msedgedriver is assuming that msedge has crashed.)
[1697043035.881][DEBUG]: Log type 'driver' lost 0 entries on destruction
[1697043035.881][DEBUG]: Log type 'browser' lost 0 entries on destruction

Take a look at the first line after the json string. I did notice that one of the parameters, the "--user-data-dir" parameter, was set to equal the same value that appeared in the message box when it appeared. Not sure what is going on here.

How to reproduce

Steps to reproduce the behavior (e.g.):

  1. Consider the example script at this gist, or write your own script that uses the msedge web driver.
  2. Run script
  3. View log and See error

Expected behavior

I would expect the msedge

Screenshots

au3web

Additional context

NA

System under test

Please complete the following information.

Danp2 commented 11 months ago

In your example script, you are calling _WD_Startup() in the wrong place, which is why you see this near the beginning of the log --

    _WD_Startup ==> Invalid value [4] : Location for Web Driver not set.

The script ran fine for me once I fixed that and some other minor issues related to paths.

session not created: DevToolsActivePort file doesn't exist

This seems to be a common problem with the Chromium-based browsers. I don't remember the solution off hand, but you may want to check the FAQ on the wiki or search the AutoIt forums.

Take a look at the first line after the json string. I did notice that one of the parameters, the "--user-data-dir" parameter, was set to equal the same value that appeared in the message box when it appeared. Not sure what is going on here.

This is normal webdriver behavior where a new user profile will be created in a temporary directory unless you specify otherwise.

Danp2 commented 11 months ago

Are you trying to run in Administrator mode? If so, then that's the issue. See https://github.com/MicrosoftEdge/EdgeWebDriver/issues/80

mlipok commented 10 months ago

https://stackoverflow.com/a/50763968/5314940

Danp2 commented 10 months ago

Closing as this appears to be environmental and not a bug in the UDF.