Jump to content

WebDriver UDF - Help & Support (II)


Danp2
 Share

Recommended Posts

How would you make this headless?  I know the chromedriver has this option but I have no idea how to incorporate it with the script.  I just want the action to be performed in the background without the window opening.  

Link to comment
Share on other sites

Hi.. i need help regarding looping using Xpath. Right now its work but i want to make it flexible looping rather than state 2 to 102. i want identify how many dropdown available and select all. Thanks in advance !!

    For $i = 2 to 102
    $LookupBtn = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[@id='SO']/option["&$i&"]")
    _WD_ElementAction($sSession, $LookupBtn, 'click')
    _WD_LoadWait($sSession, 4000)
    Next

image.png.ce8450fbea29e09678e046af6ec140f1.png

Link to comment
Share on other sites

On 7/1/2020 at 7:45 AM, Danp2 said:

@Dhanaraju Add the following line at the beginning of your script to prevent the automatic closure of an existng webdriver console --

_WD_Option('DriverClose', False)

 

Thanks for the response Danp2, it is still stopping the first process when second one starts. Below is my code, please let me know if i am missing something

Func SetupChrome($appUrl)
_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"')
_WD_Option('DriverClose', False)
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true , "args":[ "app='&$appUrl&'", "start-maximized", "disable-infobars"],"excludeSwitches":[]}}}}'
EndFunc

Link to comment
Share on other sites

Did anyone face an issue where chrome browser opens and during the session, process keeps opening for command prompt with "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe". Can someone please help to avoid this process command window?

Link to comment
Share on other sites

On 7/15/2020 at 4:54 PM, Danp2 said:

@vulcan4d Pretty sure this has already been covered in these forums. Have you tried using the forum search feature?

Surprisingly hard to find and not in the wiki but after your comment I pursued and I finally found a sample that spewed errors but I finally realized the code had to be updated.  For anyone who search and want this headless, use the following:

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true, "args": ["--headless", "--allow-running-insecure-content"] }}}}'

One thing I also noticed is that there is no confirmation in the ChromeDriver whe the session is closed when using: _WD_DeleteSession($sSession);
I'm not sure if that is normal or whether my sessions are not closing.  I have a loop where the session has to close at the end but since I don't see a confirmation I'm not sure.

 

Edited by vulcan4d
Link to comment
Share on other sites

@Dhanaraju It would be better if you had posted a functional example that we could actually run. For example --

#include "wd_helper.au3"
#include "wd_core.au3"

Local $sDesiredCapabilities

SetupChrome()
_WD_Option('DriverClose', False)
_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

If @error = $_WD_ERROR_Success Then
    _WD_Navigate($sSession, "https://www.google.com")
    _WD_LoadWait($sSession)
EndIf

_WD_DeleteSession($sSession)

Func SetupChrome()
_WD_Option('Driver', '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

Including the results from Scite then helps to diagnose any issues --

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\danpollak\Dropbox\webdriver\test.au3" /UserParams    
+>06:41:14 Starting AutoIt3Wrapper (19.1127.1402.0} from:SciTE.exe (4.2.0.0)  Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\danpollak\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\danpollak\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\danpollak\Dropbox\webdriver\test.au3
+>06:41:14 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\danpollak\Dropbox\webdriver\test.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
_WD_IsLatestRelease: True
_WDStartup: OS: WIN_10 WIN32_NT 18363 
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.3.0.4 (Up to date)
_WDStartup: WinHTTP:    1.6.4.2
_WDStartup: Driver: chromedriver.exe
_WDStartup: Params: --verbose --log-path="C:\Users\danpollak\Dropbox\webdriver\chrome.log"
_WDStartup: Port:   9515
_WDStartup: Existing instance of chromedriver.exe detected!
__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=200; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"84.0....
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"84.0.4147.89","chrome":{"chromedriverVersion":"84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310})","userDataDir":"C:\\Users\\danpollak\\AppData\\Local\\Temp\\scoped_dir26324_1963214237"},"goog:chromeOptions":{"debuggerAddress":"localhost:62679"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:virtualAuthenticators":true},"sessionId":"da772261a206b9de06719b5098795444"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/da772261a206b9de06719b5098795444/url; $sData={"url":"https://www.google.com"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/da772261a206b9de06719b5098795444/execute/sync; $sData={"script":"return document.readyState", "args":[]}
__WD_Post: StatusCode=200; ResponseText={"value":"complete"}...
_WD_ExecuteScript: {"value":"complete"}...
__WD_Delete: URL=HTTP://127.0.0.1:9515/session/da772261a206b9de06719b5098795444
__WD_Delete: StatusCode=200; ResponseText={"value":null}...
_WD_DeleteSession: {"value":null}
+>06:41:17 AutoIt3.exe ended.rc:0
+>06:41:17 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 4.063

If your goal is to run multiple Chromedriver instances, then you also need to add the following line of code before the call to _WD_Startup --

_WD_Option('DriverDetect', False)

However, I don't know why you would want to do this since a single Chromedriver instance can support multiple active sessions. Can you elaborate on your reasoning for wanting multiple active consoles?

Link to comment
Share on other sites

@Danp2 Can I use more then one attribute in an HTML tag to tell webdriver what to click on?

Example I want to click on an image until another image appears, however, the only difference between the two image tags is the title. 

Here is my code:

; 11. Click on VIEW LINE DETAILS
Do
    $viewPoLineDetails = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//img[@id='mdcaa79e9_tdrow_[C:0]_tgdet-ti[R:" & $ai & "]_img']")
    _WD_ElementAction($sSession, $viewPoLineDetails, 'click')
    Sleep(1500)
    ConsoleWrite(@CRLF & "Am I stuck at line: " & @ScriptLineNumber & @CRLF)
Until _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//img[@id='mdcaa79e9_tdrow_[C:0]_tgdet-ti[R:" & $ai & "]_img']/@title='Close Details']") <> ""

I want webdriver to check for the id and title. Both are under the same img tag. 

Here are the two element tags:

CLOSED

<img id="mdcaa79e9_tdrow_[C:0]_tgdet-ti[R:0]_img" aria-disabled="true" tabindex="-1" border="0" class="ti   " src="img_row_unselect.gif" source="img_row_unselect" imgtype=".gif" ev="false" align="top" style="display:block;margin:0px;margin-top:2px;" alt="View Details" title="View Details" draggable="false">

OPEN

<img id="mdcaa79e9_tdrow_[C:0]_tgdet-ti[R:0]_img" aria-disabled="true" tabindex="-1" border="0" class="ti   " src="img_row_select.gif" source="img_row_select" imgtype=".gif" ev="true" align="top" style="display:block;margin:0px;margin-top:2px;" alt="Close Details" title="Close Details" draggable="false">

 

Link to comment
Share on other sites

17 minutes ago, nooneclose said:

_WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//img[@id='mdcaa79e9_tdrow_[C:0]_tgdet-ti[R:" & $ai & "]_img']/@title='Close Details']")

Think you want this --

_WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//img[@id='mdcaa79e9_tdrow_[C:0]_tgdet-ti[R:" & $ai & "]_img' and @title='Close Details']")

 

Link to comment
Share on other sites

4 hours ago, Danp2 said:

@Dhanaraju It would be better if you had posted a functional example that we could actually run. For example --

#include "wd_helper.au3"
#include "wd_core.au3"

Local $sDesiredCapabilities

SetupChrome()
_WD_Option('DriverClose', False)
_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

If @error = $_WD_ERROR_Success Then
    _WD_Navigate($sSession, "https://www.google.com")
    _WD_LoadWait($sSession)
EndIf

_WD_DeleteSession($sSession)

Func SetupChrome()
_WD_Option('Driver', '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

Including the results from Scite then helps to diagnose any issues --

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\danpollak\Dropbox\webdriver\test.au3" /UserParams    
+>06:41:14 Starting AutoIt3Wrapper (19.1127.1402.0} from:SciTE.exe (4.2.0.0)  Keyboard:00000409  OS:WIN_10/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Users\danpollak\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper   SCITE_USERHOME => C:\Users\danpollak\AppData\Local\AutoIt v3\SciTE 
>Running AU3Check (3.3.14.5)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\danpollak\Dropbox\webdriver\test.au3
+>06:41:14 AU3Check ended.rc:0
>Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\danpollak\Dropbox\webdriver\test.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
_WD_IsLatestRelease: True
_WDStartup: OS: WIN_10 WIN32_NT 18363 
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.3.0.4 (Up to date)
_WDStartup: WinHTTP:    1.6.4.2
_WDStartup: Driver: chromedriver.exe
_WDStartup: Params: --verbose --log-path="C:\Users\danpollak\Dropbox\webdriver\chrome.log"
_WDStartup: Port:   9515
_WDStartup: Existing instance of chromedriver.exe detected!
__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=200; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"84.0....
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"84.0.4147.89","chrome":{"chromedriverVersion":"84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310})","userDataDir":"C:\\Users\\danpollak\\AppData\\Local\\Temp\\scoped_dir26324_1963214237"},"goog:chromeOptions":{"debuggerAddress":"localhost:62679"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:virtualAuthenticators":true},"sessionId":"da772261a206b9de06719b5098795444"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/da772261a206b9de06719b5098795444/url; $sData={"url":"https://www.google.com"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/da772261a206b9de06719b5098795444/execute/sync; $sData={"script":"return document.readyState", "args":[]}
__WD_Post: StatusCode=200; ResponseText={"value":"complete"}...
_WD_ExecuteScript: {"value":"complete"}...
__WD_Delete: URL=HTTP://127.0.0.1:9515/session/da772261a206b9de06719b5098795444
__WD_Delete: StatusCode=200; ResponseText={"value":null}...
_WD_DeleteSession: {"value":null}
+>06:41:17 AutoIt3.exe ended.rc:0
+>06:41:17 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 4.063

If your goal is to run multiple Chromedriver instances, then you also need to add the following line of code before the call to _WD_Startup --

_WD_Option('DriverDetect', False)

However, I don't know why you would want to do this since a single Chromedriver instance can support multiple active sessions. Can you elaborate on your reasoning for wanting multiple active consoles?

Hi Danp2, 

I was using old version which was not having that flag/option, now I took latest code and driverclose is working with all small chars. 

My original issue is when I don't close the chromedriver, lets say i launch a windows session (session id XX ) as Administrator user and start application exe everything looks good chrome driver starts under some session XX. Now another user uses Administrator credentials and launch another session XY and start exe, Chrome browser is being opened in the first session XX itself where chrome driver is running.  

How can I open application in the same session when user clicks on exe? if I close previous chrome driver and start new chromedriver each time new session opens that is the only way i am able to launch session there but problem is I cant open them simultaneously which is not good. 

Dhanaraju

Link to comment
Share on other sites

Hi @Dhanaraju,

It sounds like you are logging into some form of remote or virtual desktop. Can you provide a better description of your operating environment?

You probably need to adjust the baseURL for each session. If each "session" is given a unique IP address, then you do something like this --

$sSessionIP = _GetIP()
_WD_Option('BaseURL', $sSessionIP)

That will allow each session to communicate with it's own instance of Chromedriver. Depending on your environment, you may run into a conflict with ports as well.

P.S. Please don't quote entire posts when responding. Unnecessary quoting can make it more difficult to follow a thread

Link to comment
Share on other sites

32 minutes ago, Danp2 said:

Hi @Dhanaraju,

It sounds like you are logging into some form of remote or virtual desktop. Can you provide a better description of your operating environment?

You probably need to adjust the baseURL for each session. If each "session" is given a unique IP address, then you do something like this --

$sSessionIP = _GetIP()
_WD_Option('BaseURL', $sSessionIP)

That will allow each session to communicate with it's own instance of Chromedriver. Depending on your environment, you may run into a conflict with ports as well.

P.S. Please don't quote entire posts when responding. Unnecessary quoting can make it more difficult to follow a thread

yes @Danp2 we have a windows 2016 machine where these apps are hosted as remote apps. users login to this windows remote desktop and launch this application. If i try to start multiple chrome driver then i will have port issues right. Technically it should be as simple as starting chrome driver on port and all users should be able to launch their apps in their own sessions by contacting the chrome driver. Not sure if i am doing something wrong. Also how will getting IP will help as it is goign to give same IP for all users as it is same windows 2016 machine where app.exe is placed.

Link to comment
Share on other sites

3 hours ago, Danp2 said:

@Dhanaraju In that scenario, each session would need to run it's own copy of Chromedriver AFAIK. Otherwise, the Chrome instance will get created in the wrong session as you've discovered.

Maybe the clients should have their own chromedriver.exe and log files in their local folder(ie, @MyDocumentsDir) and, in the SetupChrome() of the windows 2016 machine, make reference to the location of local files as follows:

_WD_Option('Driver', @MyDocumentsDir & '\chromedriver.exe')
_WD_Option('DriverParams', '--log-path=' & @MyDocumentsDir & '\chrome.log')

 

Edited by CYCho
Link to comment
Share on other sites

I have been using WebDriver successfully but I have 3 issues.  Here a very basic snippet :

#include "wd_core.au3"
#include "wd_helper.au3"

Global $sDesiredCapabilities
$_WD_DEBUG = $_WD_DEBUG_Info ; $_WD_DEBUG_None

SetupChrome()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)

Sleep (5000)

_WD_Shutdown()

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":["disable-infobars"]}}}}'
EndFunc

And the result :

_WD_IsLatestRelease: 
_WD_IsLatestRelease ==> Send / Recv error
_WDStartup: OS: WIN_7 WIN32_NT 7601 Service Pack 1
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.3.0.4 (Update status unknown [6])
_WDStartup: WinHTTP:    1.6.4.2
_WDStartup: Driver: chromedriver.exe
_WDStartup: Params: --log-path="C:\Applications\AutoIt\WebDriver\chrome.log"
_WDStartup: Port:   9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["disable-infobars"]}}}}
__WD_Post: StatusCode=200; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"84.0....
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"84.0.4147.89","chrome":{"chromedriverVersion":"84.0.4147.30 (48b3e868b4cc0aa7e8149519690b6f6949e110a8-refs/branch-heads/4147@{#310})","userDataDir":"C:\\Users\\xxxx\\AppData\\Local\\Temp\\scoped_dir6504_1012405157"},"goog:chromeOptions":{"debuggerAddress":"localhost:49292"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:virtualAuthenticators":true},"sessionId":"7d9ce21369f701ae52916393a6cbc5ae"}}

Issue 1 : _WD_IsLatestRelease is returning @error = 2

Issue 2 : disable-infobars is not removing the annoying message : "Chrome is being controlled by automated test software"

Issue 3 : (unshown)  : how do I get rid of pop-up windows that randomly appear (e.g. asking to answer a small survey)

Thanks.

Link to comment
Share on other sites

12 minutes ago, Aether said:

Issue 1 : _WD_IsLatestRelease is returning @error = 2

Are you sure? It actually appears to be returning a 6, which is the value of $_WD_ERROR_SendRecv

To help diagnose the issue, you could try commenting out the following line in _WD_IsLatestRelease so that you get additional debugging details --

$_WD_DEBUG = $_WD_DEBUG_None
Quote

Issue 2 : disable-infobars is not removing the annoying message

Try this instead --

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

Issue 3 : (unshown)  : how do I get rid of pop-up windows that randomly appear (e.g. asking to answer a small survey)

Isn't this a generic browser issue rather than a webdriver one?

Link to comment
Share on other sites

Issue 2 solved - Thanks

Issue 1 (commented $_WD_DEBUG = $_WD_DEBUG_None) :

__WD_Get: URL=https://github.com/Danp2/WebDriver/releases/latest
__WD_Get: StatusCode=0; $iResult = 6; $sResponseText=WinHTTP request timed out before Webdriver...
__WD_Get ==> Send / Recv error: WinHTTP request timed out before Webdriver
_WD_IsLatestRelease: 
_WD_IsLatestRelease ==> Send / Recv error
_WDStartup: OS: WIN_7 WIN32_NT 7601 Service Pack 1
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.3.0.4 (Update status unknown [6])
_WDStartup: WinHTTP:    1.6.4.2
_WDStartup: Driver: chromedriver.exe
_WDStartup: Params: --log-path="C:\Applications\AutoIt\WebDriver\chrome.log"
_WDStartup: Port:   9515

You are right, it is error 6 :>

Issue 3 : Yes I suppose it is, but with IE in the same site, it doesn't show those popup, I was hoping there was way with Chrome to solve it.

Link to comment
Share on other sites

  • Jos locked this topic
Guest
This topic is now closed to further replies.
 Share

  • Recently Browsing   0 members

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