Jump to content

WebDriver UDF (W3C compliant version) - 2024/02/19


Danp2
 Share

Recommended Posts

On 6/21/2019 at 2:30 PM, Danp2 said:

@MilenPThis topic has been previously discussed. Try reviewing this post --

 

 

Hi @Danp2, Is there an option, to use the Default profile of the Firefox (with the Gecko driver), but without starting the firefox with --marionette manually?

 

Quote


  • Start Firefox manually with the "--marionette" option
  • Use these settings to connect to the existing browser instance

_WD_Option('DriverParams', '--log trace --connect-existing  --marionette-port 2828')


 

 

Thank you,

Milen

Link to comment
Share on other sites

On 6/19/2019 at 2:25 PM, Danp2 said:

I believe this is normal (msg is informational only). Did you experience any other issues when using Chromedriver?

The driver is not getting launched. That's the problem

Link to comment
Share on other sites

@linhoanh The element is being found, but it apparently isn't clickable. You'll need to figure out why. Perhaps you've identified the wrong element or maybe you must perform some other action, such as logging in as a valid user, before the element is enabled.

P.S. Why do you need to automate subscribing to a Youtube channel? This seems odd. Please explain.

Link to comment
Share on other sites

I don't believe this issue has been raised (at least not to my knowledge) and I was wondering if someone could help or let me know that they are also experiencing the problem (so I don't go mad!)

I am trying to populate an input box on a website, but it will not populate using the following:

<Snip>

Thanks a ton for your help.

 

@NSearch you seem to have not bothered to read our forum rules before posting. Please read them now, especially the section on Captcha and you will see why your post has been removed.

Edited by JLogan3o13
Link to comment
Share on other sites

6 hours ago, NSearch said:

I don't believe this issue has been raised (at least not to my knowledge) and I was wondering if someone could help or let me know that they are also experiencing the problem (so I don't go mad!)

I am trying to populate an input box on a website, but it will not populate using the following:

<Snip>

Thanks a ton for your help.

 

@NSearch you seem to have not bothered to read our forum rules before posting. Please read them now, especially the section on Captcha and you will see why your post has been removed.

I am not attempting to circumvent or break any security protocols -- in fact, I will say, it is impossible to do so on the captcha they use. I am simply trying to enter the Captcha (manually) into a GUI and have the GUI insert it into the input box.

Why am I doing this? So that I do not have to copy and paste the tracking and invoice numbers into the screen. The input boxes for those have no issue accepting the values I send.

 

Link to comment
Share on other sites

  • 2 weeks later...
On 1/17/2018 at 5:14 PM, Danp2 said:

Introduction

This UDF will allow you to interact with any browser that supports the W3C WebDriver specifications. Supporting multiple browsers via the same code base is now possible with just a few configuration settings.

Requirements

Function List

Core Functions

  • _WD_CreateSession($sDesiredCapabilities='{}')
  • _WD_DeleteSession($sSession)
  • _WD_Status()
  • _WD_Timeouts($sSession, $sTimeouts = '')
  • _WD_Navigate($sSession, $sURL)
  • _WD_Action($sSession, $sCommand)
  • _WD_Window($sSession, $sCommand, $sOption = '')
  • _WD_FindElement($sSession, $sStrategy, $sSelector, $sStartElement = "", $lMultiple = False)
  • _WD_ElementAction($sSession, $sElement, $sCommand, $sOption='')
  • _WD_ExecuteScript($sSession, $sScript, $sArguments="[]")
  • _WD_Alert($sSession, $sCommand, $sOption = '')
  • _WD_GetSource($sSession)
  • _WD_Cookies($sSession, $sCommand, $sOption = '')
  • _WD_Option($sOption, $vValue = "")
  • _WD_Startup()
  • _WD_Shutdown()

Helper Functions

  • _WD_NewTab($sSession, $lSwitch = True, $iTimeout = -1, $sURL = "", $sFeatures = "")
  • _WD_Attach($sSession, $sString, $sMode = 'title')
  • _WD_LinkClickByText($sSession, $sText, $lPartial = True)
  • _WD_WaitElement($sSession, $sElement, $sStrategy, $sSelector[, $iDelay = 0[, $iTimeout = -1]])
  • _WD_GetMouseElement($sSession)
  • _WD_GetElementFromPoint($sSession, $iX, $iY)
  • _WD_LastHTTPResult()
  • _WD_GetFrameCount()
  • _WD_IsWindowTop()
  • _WD_FrameEnter($sIndexOrID)
  • _WD_FrameLeave()
  • _WD_HighlightElement($sSession, $sElement[, $iMethod = 1])
  • _WD_HighlightElements($sSession, $aElements[, $iMethod = 1])
  • _WD_jQuerify($sSession)
  • WD_ElementOptionSelect($sSession, $sStrategy, $sSelector, $sStartElement = "")
  • _WD_ConsoleVisible($lVisible = False)

Source Code

You will always be able to find the latest version in the GitHub Repo 

Help / Support

Please post any questions, suggestions or errors in the GH&S thread.

https://www.autoitscript.com/forum/topic/192730-webdriver-udf-help-support/

How to set back the cookies obtained from 'getall' ? thanks.

#include "wd_core.au3"

Local $url = "https://www.google.com"
Local $sDesiredCapabilities
Local $sCookie
Local $firsttime = 0 

run()

func run 

SetupChrome()
_WD_Startup()
$Session = _WD_CreateSession($sDesiredCapabilities)
Sleep(2000)
_WD_Navigate($Session, $url)

; for the fist time to get all the cookies and stored it for latter use.
if firsttime==0 then
  sleep(60000) ; login to get all the cookies
 $sCookie = _WD_Cookies($Session, 'getall')
endif
; for the other time, add storaged cookies so as to keep the logged in status.

_WD_Cookies($Session, 'add', $sCookie)
_WD_Navigate($Session, $url)


_WD_Shutdown()
firsttime = firsttime +1
EndFunc

Func SetupChrome()
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true}}}}'
EndFunc

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

@jiataifeng No need to quote the entire initial post when asking a question. 🙄

This isn't something that I tried myself. I suspect that you will need to parse the JSON string to obtain each individual cookie, and then call the function to add each one individually.

P.S. This question would be better asked in this thread in the GH&S section.

Link to comment
Share on other sites

#include <Constants.au3>
#include "wd_core.au3"
#include "wd_helper.au3"

Local $sDesiredCapabilities, $sSession
SetupChrome()

_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://www.nbcnews.com/")
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='content']/div/div[5]/div/div/div[2]/div/section/div[2]/div/div[1]/article/div[2]/h2/a/span")
_WD_ElementAction($sSession, $sElement, 'click')

Sleep(3000)
_WD_NewTab($sSession)
_WD_Navigate($sSession, "http://yahoo.com")

Sleep(3000)
_WD_Attach($sSession, "nbcnews.com", "URL")

Sleep(3000)
_WD_Attach($sSession, "yahoo.com", "URL")
Sleep(1000)
_WD_Window($sSession,"close")   ;close tab

Sleep(3000)  ;these following lines will longer work, but if they're moved above _WD_Window($sSession,"close"), they work OK
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='hfs-header']/nav/div[2]/div[3]/div[1]/ul/li[1]/a")
_WD_ElementAction($sSession, $sElement, 'click')



Func SetupChrome()
    _WD_Option('Driver', 'C:\Users\Tri Tran\Documents\ChromeDriver\chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":[' & """user-data-dir=C:\\ChromeAutoProfile"","  & " ""disable-infobars""" & "" & '] }}}}'
EndFunc


;------partial log---------------------------------------------------------------------
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"https://www.yahoo.com/"}...
_WD_Action: {"value":"https://www.yahoo.com/"}
__WD_Delete: URL=HTTP://127.0.0.1:9515/session/09ae64ce672ad64e4454647c9a4e27fe/window
__WD_Delete: StatusCode=200; ResponseText={"value":["CDwindow-9E1340F16BF28DDB2E2911BDE2B2720A"]}
_WD_Window: {"value":["CDwindow-9E1340F16BF28DDB2E2911BDE2B2720A"]}...
__WD_Post: URL=HTTP://127.0.0.1:9515/session/09ae64ce672ad64e4454647c9a4e27fe/element; $sData={"using":"xpath","value":"//*[@id='hfs-header']/nav/div[2]/div[3]/div[1]/ul/li[1]/a"}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such window","message":"target window already closed\nfrom unknown error: web view not found\n  (Session info: chrome=75.0.3770.100)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00963C43+1457219]\n\tOrdinal0 [0x008DC471+902257]\n\tOrdinal0 [0x0087D54F+513359]\n\tOrdinal0 [0x0086DA68+449128]\n\tOrdinal0 [0x0082FF2D+196397]\n\tOrdinal0 [0x00837446+226374]\n\tOrdinal0 [0x0082F4AB+193707]\n\tOrdinal0 [0x00814160+82272]\n\tOrdinal0 [0x008156E6+87782]\n\tOrdinal0 [0x008155F0+87536]\n\tGetHandleVerifier [0x00ACC781+1305121]\n\tGetHandleVerifier [0x00A14B0E+552366]\n\tGetHandleVerifier [0x00A149D6+552054]\n\tOrdinal0 [0x00971FA7+1515431]\n\tGetHandleVerifier [0x00A15036+553686]\n\tOrdinal0 [0x008F300F+995343]\n\tOrdinal0 [0x008FF65B+1046107]\n\tOrdinal0 [0x008FF7AA+1046442]\n\tOrdinal0 [0x008FE7C5+1042373]\n\tBaseThreadInitThunk [0x76396359+25]\n\tRtlGetAppContainerNamedObjectPath [0x77947A94+228]\n\tRtlGetAppContainerNamedObjectPath [0x77947A64+180]\n"}}
_WD_FindElement: {"value":{"error":"no such window","message":"target window already closed\nfrom unknown error: web view not found\n  (Session info: chrome=75.0.3770.100)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00963C43+1457219]\n\tOrdinal0 [0x008DC471+902257]\n\tOrdinal0 [0x0087D54F+513359]\n\tOrdinal0 [0x0086DA68+449128]\n\tOrdinal0 [0x0082FF2D+196397]\n\tOrdinal0 [0x00837446+226374]\n\tOrdinal0 [0x0082F4AB+193707]\n\tOrdinal0 [0x00814160+82272]\n\tOrdinal0 [0x008156E6+87782]\n\tOrdinal0 [0x008155F0+87536]\n\tGetHandleVerifier [0x00ACC781+1305121]\n\tGetHandleVerifier [0x00A14B0E+552366]\n\tGetHandleVerifier [0x00A149D6+552054]\n\tOrdinal0 [0x00971FA7+1515431]\n\tGetHandleVerifier [0x00A15036+553686]\n\tOrdinal0 [0x008F300F+995343]\n\tOrdinal0 [0x008FF65B+1046107]\n\tOrdinal0 [0x008FF7AA+1046442]\n\tOrdinal0 [0x008FE7C5+1042373]\n\tBaseThreadInitThunk [0x76396359+25]\n\tRtlGetAppContainerNamedObjectPath [0x77947A94+228]\n\tRtlGetAppContainerNamedObjectPath [0x77947A64+180]\n"}}
_WD_FindElement ==> Webdriver Exception: HTTP status = 404
__WD_Post: URL=HTTP://127.0.0.1:9515/session/09ae64ce672ad64e4454647c9a4e27fe/element//click; $sData={"id":""}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such window","message":"target window already closed\nfrom unknown error: web view not found\n  (Session info: chrome=75.0.3770.100)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00963C43+1457219]\n\tOrdinal0 [0x008DC471+902257]\n\tOrdinal0 [0x0087D54F+513359]\n\tOrdinal0 [0x0086DA68+449128]\n\tOrdinal0 [0x0082FF2D+196397]\n\tOrdinal0 [0x00837446+226374]\n\tOrdinal0 [0x0082F4AB+193707]\n\tOrdinal0 [0x00814160+82272]\n\tOrdinal0 [0x008156E6+87782]\n\tOrdinal0 [0x008155F0+87536]\n\tGetHandleVerifier [0x00ACC781+1305121]\n\tGetHandleVerifier [0x00A14B0E+552366]\n\tGetHandleVerifier [0x00A149D6+552054]\n\tOrdinal0 [0x00971FA7+1515431]\n\tGetHandleVerifier [0x00A15036+553686]\n\tOrdinal0 [0x008F300F+995343]\n\tOrdinal0 [0x008FF65B+1046107]\n\tOrdinal0 [0x008FF7AA+1046442]\n\tOrdinal0 [0x008FE7C5+1042373]\n\tBaseThreadInitThunk [0x76396359+25]\n\tRtlGetAppContainerNamedObjectPath [0x77947A94+228]\n\tRtlGetAppContainerNamedObjectPath [0x77947A64+180]\n"}}
_WD_ElementAction: {"value":{"error":"no such window","message":"target window already closed\nfrom unknown error: web ...
_WD_ElementAction ==> Webdriver Exception: {"value":{"error":"no such window","message":"target window already closed\nfrom unknown error: web view not found\n  (Session info: chrome=75.0.3770.100)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00963C43+1457219]\n\tOrdinal0 [0x008DC471+902257]\n\tOrdinal0 [0x0087D54F+513359]\n\tOrdinal0 [0x0086DA68+449128]\n\tOrdinal0 [0x0082FF2D+196397]\n\tOrdinal0 [0x00837446+226374]\n\tOrdinal0 [0x0082F4AB+193707]\n\tOrdinal0 [0x00814160+82272]\n\tOrdinal0 [0x008156E6+87782]\n\tOrdinal0 [0x008155F0+87536]\n\tGetHandleVerifier [0x00ACC781+1305121]\n\tGetHandleVerifier [0x00A14B0E+552366]\n\tGetHandleVerifier [0x00A149D6+552054]\n\tOrdinal0 [0x00971FA7+1515431]\n\tGetHandleVerifier [0x00A15036+553686]\n\tOrdinal0 [0x008F300F+995343]\n\tOrdinal0 [0x008FF65B+1046107]\n\tOrdinal0 [0x008FF7AA+1046442]\n\tOrdinal0 [0x008FE7C5+1042373]\n\tBaseThreadInitThunk [0x76396359+25]\n\tRtlGetAppContainerNamedObjectPath [0x77947A94+228]\n\tRtlGetAppContainerNamedObjectPath [0x77947A64+180]\n"}}
+>11:34:24 AutoIt3.exe ended.rc:0
+>11:34:24 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 29.92

@Danp2 Here's the code that shows that after function _WD_Window($sSession,"close") is called, the $sSession is no longer valid.

Link to comment
Share on other sites

@Holycow I took a look at this, and I believe there are two issues --

  1. After calling _WD_Window($sSession,"close"), you will need to call _WD_Attach to reestablish the current tab. Haven't really thought about the ramifications, but I guess it's possible to have this done automatically following a close. Thoughts?
     
  2. _WD_Attach  tries to save the current tab before attempting to find the designated tab. This fails, because there isn't a "current" tab as far as the webdriver is concerned, and so the function returns an error without actually trying to switch tabs
Link to comment
Share on other sites

@Danp2  I tried again with your 1st advice, take a look a the partial log attached.  nothing works after close because the session id is no longer valid.  and any following command would require a valid session id.

#include <Constants.au3>
#include "wd_core.au3"
#include "wd_helper.au3"

Local $sDesiredCapabilities, $sSession
SetupChrome()

_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://www.nbcnews.com/")
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='content']/div/div[5]/div/div/div[2]/div/section/div[2]/div/div[1]/article/div[2]/h2/a/span")
_WD_ElementAction($sSession, $sElement, 'click')

Sleep(3000)
_WD_NewTab($sSession)
_WD_Navigate($sSession, "http://yahoo.com")

Sleep(3000)
_WD_Attach($sSession, "nbcnews.com", "URL")

Sleep(3000)
_WD_Attach($sSession, "yahoo.com", "URL")
Sleep(1000)
ConsoleWrite("about to close tab" & @CRLF)

_WD_Window($sSession,"close")   ;close tab

ConsoleWrite("about to attach" & @CRLF)

Sleep(3000)
_WD_Attach($sSession, "nbcnews.com", "URL")

Sleep(3000)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='hfs-header']/nav/div[2]/div[3]/div[1]/ul/li[1]/a")
_WD_ElementAction($sSession, $sElement, 'click')



Func SetupChrome()
    _WD_Option('Driver', 'C:\Users\Tri Tran\Documents\ChromeDriver\chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":[' & """user-data-dir=C:\\ChromeAutoProfile"","  & " ""disable-infobars""" & "" & '] }}}}'
EndFunc


;------------------------------------------------------------------------------
_WD_Action: {"value":"https://www.yahoo.com/"}
about to close tab
__WD_Delete: URL=HTTP://127.0.0.1:9515/session/4a796e89537021ae025f57665f5375e0/window
__WD_Delete: StatusCode=200; ResponseText={"value":["CDwindow-19B82533A363BBD2AC3A3D7FFA71BF7E"]}
_WD_Window: {"value":["CDwindow-19B82533A363BBD2AC3A3D7FFA71BF7E"]}...
about to attach
__WD_Get: URL=HTTP://127.0.0.1:9515/session/4a796e89537021ae025f57665f5375e0/window
__WD_Get: StatusCode=404; $iResult = 0; $sResponseText={"value":{"error":"no such window","message":"target window already closed\nfrom unknown error: web ...
_WD_Window: {"value":{"error":"no such window","message":"target window already closed\nfrom unknown error: web ...
_WD_Window ==> Webdriver Exception: HTTP status = 404
_WD_Attach ==> General Error
__WD_Post: URL=HTTP://127.0.0.1:9515/session/4a796e89537021ae025f57665f5375e0/element; $sData={"using":"xpath","value":"//*[@id='hfs-header']/nav/div[2]/div[3]/div[1]/ul/li[1]/a"}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such window","message":"target window already closed\nfrom unknown error: web view not found\n  (Session info: chrome=75.0.3770.100)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00963C43+1457219]\n\tOrdinal0 [0x008DC471+902257]\n\tOrdinal0 [0x0087D54F+513359]\n\tOrdinal0 [0x0086DA68+449128]\n\tOrdinal0 [0x0082FF2D+196397]\n\tOrdinal0 [0x00837446+226374]\n\tOrdinal0 [0x0082F4AB+193707]\n\tOrdinal0 [0x00814160+82272]\n\tOrdinal0 [0x008156E6+87782]\n\tOrdinal0 [0x008155F0+87536]\n\tGetHandleVerifier [0x00ACC781+1305121]\n\tGetHandleVerifier [0x00A14B0E+552366]\n\tGetHandleVerifier [0x00A149D6+552054]\n\tOrdinal0 [0x00971FA7+1515431]\n\tGetHandleVerifier [0x00A15036+553686]\n\tOrdinal0 [0x008F300F+995343]\n\tOrdinal0 [0x008FF65B+1046107]\n\tOrdinal0 [0x008FF7AA+1046442]\n\tOrdinal0 [0x008FE7C5+1042373]\n\tBaseThreadInitThunk [0x76396359+25]\n\tRtlGetAppContainerNamedObjectPath [0x77947A94+228]\n\tRtlGetAppContainerNamedObjectPath [0x77947A64+180]\n"}}
_WD_FindElement: {"value":{"error":"no such window","message":"target window already closed\nfrom unknown error: web view not found\n  (Session info: chrome=75.0.3770.100)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00963C43+1457219]\n\tOrdinal0 [0x008DC471+902257]\n\tOrdinal0 [0x0087D54F+513359]\n\tOrdinal0 [0x0086DA68+449128]\n\tOrdinal0 [0x0082FF2D+196397]\n\tOrdinal0 [0x00837446+226374]\n\tOrdinal0 [0x0082F4AB+193707]\n\tOrdinal0 [0x00814160+82272]\n\tOrdinal0 [0x008156E6+87782]\n\tOrdinal0 [0x008155F0+87536]\n\tGetHandleVerifier [0x00ACC781+1305121]\n\tGetHandleVerifier [0x00A14B0E+552366]\n\tGetHandleVerifier [0x00A149D6+552054]\n\tOrdinal0 [0x00971FA7+1515431]\n\tGetHandleVerifier [0x00A15036+553686]\n\tOrdinal0 [0x008F300F+995343]\n\tOrdinal0 [0x008FF65B+1046107]\n\tOrdinal0 [0x008FF7AA+1046442]\n\tOrdinal0 [0x008FE7C5+1042373]\n\tBaseThreadInitThunk [0x76396359+25]\n\tRtlGetAppContainerNamedObjectPath [0x77947A94+228]\n\tRtlGetAppContainerNamedObjectPath [0x77947A64+180]\n"}}
_WD_FindElement ==> Webdriver Exception: HTTP status = 404
__WD_Post: URL=HTTP://127.0.0.1:9515/session/4a796e89537021ae025f57665f5375e0/element//click; $sData={"id":""}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such window","message":"target window already closed\nfrom unknown error: web view not found\n  (Session info: chrome=75.0.3770.100)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00963C43+1457219]\n\tOrdinal0 [0x008DC471+902257]\n\tOrdinal0 [0x0087D54F+513359]\n\tOrdinal0 [0x0086DA68+449128]\n\tOrdinal0 [0x0082FF2D+196397]\n\tOrdinal0 [0x00837446+226374]\n\tOrdinal0 [0x0082F4AB+193707]\n\tOrdinal0 [0x00814160+82272]\n\tOrdinal0 [0x008156E6+87782]\n\tOrdinal0 [0x008155F0+87536]\n\tGetHandleVerifier [0x00ACC781+1305121]\n\tGetHandleVerifier [0x00A14B0E+552366]\n\tGetHandleVerifier [0x00A149D6+552054]\n\tOrdinal0 [0x00971FA7+1515431]\n\tGetHandleVerifier [0x00A15036+553686]\n\tOrdinal0 [0x008F300F+995343]\n\tOrdinal0 [0x008FF65B+1046107]\n\tOrdinal0 [0x008FF7AA+1046442]\n\tOrdinal0 [0x008FE7C5+1042373]\n\tBaseThreadInitThunk [0x76396359+25]\n\tRtlGetAppContainerNamedObjectPath [0x77947A94+228]\n\tRtlGetAppContainerNamedObjectPath [0x77947A64+180]\n"}}
_WD_ElementAction: {"value":{"error":"no such window","message":"target window already closed\nfrom unknown error: web ...
_WD_ElementAction ==> Webdriver Exception: {"value":{"error":"no such window","message":"target window already closed\nfrom unknown error: web view not found\n  (Session info: chrome=75.0.3770.100)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00963C43+1457219]\n\tOrdinal0 [0x008DC471+902257]\n\tOrdinal0 [0x0087D54F+513359]\n\tOrdinal0 [0x0086DA68+449128]\n\tOrdinal0 [0x0082FF2D+196397]\n\tOrdinal0 [0x00837446+226374]\n\tOrdinal0 [0x0082F4AB+193707]\n\tOrdinal0 [0x00814160+82272]\n\tOrdinal0 [0x008156E6+87782]\n\tOrdinal0 [0x008155F0+87536]\n\tGetHandleVerifier [0x00ACC781+1305121]\n\tGetHandleVerifier [0x00A14B0E+552366]\n\tGetHandleVerifier [0x00A149D6+552054]\n\tOrdinal0 [0x00971FA7+1515431]\n\tGetHandleVerifier [0x00A15036+553686]\n\tOrdinal0 [0x008F300F+995343]\n\tOrdinal0 [0x008FF65B+1046107]\n\tOrdinal0 [0x008FF7AA+1046442]\n\tOrdinal0 [0x008FE7C5+1042373]\n\tBaseThreadInitThunk [0x76396359+25]\n\tRtlGetAppContainerNamedObjectPath [0x77947A94+228]\n\tRtlGetAppContainerNamedObjectPath [0x77947A64+180]\n"}}
+>13:26:41 AutoIt3.exe ended.rc:0
+>13:26:41 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 33.12

 

Link to comment
Share on other sites

@Holycow I failed in my earlier post to convey the proper message. It wasn't to give you advice; it was actually to acknowledge that you've identified an issue with how the UDF is currently coded.

The session id is still valid. Run this modified version of your code to see --

#include <Constants.au3>
#include "wd_core.au3"
#include "wd_helper.au3"

Local $sDesiredCapabilities, $sSession
SetupChrome()
_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

_WD_Navigate($sSession, "https://www.nbcnews.com/")
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='content']/div/div[5]/div/div/div[2]/div/section/div[2]/div/div[1]/article/div[2]/h2/a/span")
_WD_ElementAction($sSession, $sElement, 'click')

_WD_NewTab($sSession)
_WD_Navigate($sSession, "http://yahoo.com")

_WD_Attach($sSession, "nbcnews.com", "URL")

Sleep(3000)
_WD_Attach($sSession, "yahoo.com", "URL")
Sleep(1000)

$sHandles = _WD_Window($sSession,"close")   ;close tab
ConsoleWrite('handles=' & $sHandles & @CRLF)

$oJson = Json_Decode($sHandles)
$sResult = Json_Get($oJson, "[value]")
_WD_Window($sSession, 'Switch', '{"handle":"' & $sResult[0] & '"}') ; Switch to the remaining tab

Sleep(3000)  ;these following lines will longer work, but if they're moved above _WD_Window($sSession,"close"), they work OK
_WD_Attach($sSession, "nbcnews.com", "URL")
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='hfs-header']/nav/div[2]/div[3]/div[1]/ul/li[1]/a")
_WD_ElementAction($sSession, $sElement, 'click')


Func SetupChrome()
    _WD_Option('Driver', 'chromedriver.exe')
    _WD_Option('Port', 9515)
    _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":[' & """user-data-dir=C:\\ChromeAutoProfile"","  & " ""disable-infobars""" & "" & '] }}}}'
EndFunc

 

Link to comment
Share on other sites

@danp123  Thank you Dan, your change made it work now. 
Let me try to understand your code to see how you got this working. 
I appreciate for your help. 

Please do let me know if you have the library functions updated and I will download a new copy.

Link to comment
Share on other sites

ResponseText={"value":null}

ResponseText={"value":["TX0058_2","TX0058_5"]}

As shown above.

1, how to determine whether ResponseText is null or non-empty?

2, how to get "TX0058_2" and "TX0058_5" in ResponseText?

To put it another way:

how do I convert the result of ResponseText into an array or string form?

How do I use Json_Decode and Json_Get?

I didn't see the detailed help file, so I didn't understand how to use these two functions.

Edited by Letraindusoir
Link to comment
Share on other sites

  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 2024/02/19
  • Melba23 pinned this topic

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

×
×
  • Create New...