Jump to content

WebDriver UDF - Help & Support (II)


Danp2
 Share

Recommended Posts

@Aether Please run the following and post the Scite console output --

#include "WinHttp.au3"

Local $sResponseText = ""
Local $sGitURL = "https://github.com/Danp2/WebDriver/releases/latest"
Local $aURL = _WinHttpCrackUrl($sGitURL)

If IsArray($aURL) Then
    ; Initialize and get session handle
    Local $hOpen = _WinHttpOpen()

    _WinHttpSetTimeouts($hOpen, 0, 60000, 30000, 30000)

    ; Get connection handle
    Local $hConnect = _WinHttpConnect($hOpen, $aURL[2], $aURL[3])

    If @error Then
        ConsoleWrite("Error opening connection! (" & @error & ")" & @crlf)
    Else
        Switch $aURL[1]
            Case $INTERNET_SCHEME_HTTP
                $sResponseText = _WinHttpSimpleRequest($hConnect, "GET", $aURL[6] & $aURL[7])
            Case $INTERNET_SCHEME_HTTPS
                $sResponseText = _WinHttpSimpleSSLRequest($hConnect, "GET", $aURL[6] & $aURL[7])
        EndSwitch

        ConsoleWrite("@error=" & @error & @crlf)
    EndIf

    _WinHttpCloseHandle($hConnect)
    _WinHttpCloseHandle($hOpen)
EndIf

 

Link to comment
Share on other sites

@Aether Looking at the header for _WinHttpSimpleSSLRequest, @error = 2 means it could not send request. Looks like this is  --

  • _WinHttpSimpleSSLRequest calls _WinHttpSimpleSendSSLRequest
  • _WinHttpSimpleSendSSLRequest calls _WinHttpSendRequest
  • _WinHttpSendRequest calls the DLL function WinHttpSendRequest, which is failing

Any thoughts on why this might be happening? Any proxy or firewalls involved?

Link to comment
Share on other sites

No proxy. No firewall (beside win7).  If it was a proxy/FW issue, shouldn't it fail with InetRead too ?

I did your test with Win10 machine and it is working fine under the same local network.  It seems it is the Win7 machine that has the problem.  Maybe bad winhttp.dll ?

I tried to explicitly open port 443 in FW without success. I tried running x64 same issue.

Edit :

Well I am quite lost now, I tested your script on multiple sites (Microsoft, autoit, google, yahoo, etc.) and they all work well. I couldn't find another site where it is not working except github.

ReEdit :

I converted your script into ObjCreate("WinHttp.WinHttpRequest.5.1").  And the exact phenomenon happens.  I can read any site beside github.  It must dislike me.

Edited by Aether
Link to comment
Share on other sites

On 7/17/2020 at 4:54 AM, Danp2 said:

@vulcan4d Glad you were able to get the headless option working. Can you explain what type of confirmation you were expecting after calling _WD_DeleteSession?

In general, you want to check @error after each call to a UDF function to detect success / failure.

ChromeDriver creates a new line with "Dev Tools listening on" followed with an assigned port.  I assumed the session was kept open because eventually after a several hours AutoIt crashes stating some "memory allocation error".  Sorry next time I'll take note of the error better and edit this post.  I assumed the sessions did not close and eventually it hit some sort of resource limit.  I'll do some logging with @error to see the results.  Thanks for the tip!

Link to comment
Share on other sites

On 7/12/2020 at 1:59 PM, crazycrash said:

I fixed the post above trying to get the xpath relative to another previously found element. Below my attempt at getting a child element of a previously found element. (Similar to the javascribt above). However, this is also failing

Figured out that you have to use a relative xpath for this Webdriver function to work correctly. Try your code again after making this one change --

Local $sXpathUserContent = ".//div[contains(@class, 'userContent ')]" ;xpath within element $PostContent to usercontent

 

Link to comment
Share on other sites

On 7/21/2020 at 3:18 PM, Danp2 said:

Figured out that you have to use a relative xpath for this Webdriver function to work correctly. Try your code again after making this one change --

Local $sXpathUserContent = ".//div[contains(@class, 'userContent ')]" ;xpath within element $PostContent to usercontent

 

Thanks, so many hours and its a . 😃 All the scripts work flawless. Cheers!

Link to comment
Share on other sites

Good Morning Danp,

 

Chrome browser opened and Unable to send data into Website text field.

I installed Chrome Driver and CRX extension in Chrome. Please help i m new to Auto IT. Your help is really appreciated 

 

I receiving following error

WD_IsLatestRelease: True
_WD_IsLatestRelease ==> Success
_WDStartup: OS:    WIN_10 WIN32_NT 18363 
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.3.0.4 (Up to date)
_WDStartup: Driver:    C:\Users\jiya\Desktop\AutoIT Script\chromedriver.exe
_WDStartup: Params:    --log-path="C:\Users\jiya\Desktop\A\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, "args":["start-maximized", "disable-infobars"], "prefs": {"profile.default_content_setting_values.javascript": 2}}}}}
__WD_Post: StatusCode=0; 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\\jiya\\AppData\\Local\\Temp\\scoped_dir4988_1002928166"},"goog:chromeOptions":{"debuggerAddress":"localhost:50909"},"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":"3760f251ffb2b0faf6cbbaaf666a02f4"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/3760f251ffb2b0faf6cbbaaf666a02f4/url; $sData={"url":"https://omd.infomc.biz/iPC/Login.aspx?cmdLogout=true"}
__WD_Post: StatusCode=0; ResponseText={"value":null}...
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/3760f251ffb2b0faf6cbbaaf666a02f4/element; $sData={"using":"xpath","value":"//input[@id='txtUserName']"}
__WD_Post: StatusCode=0; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"b352cef7-f9dc-4147-96d3-d31f03164f9d"}}...
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"b352cef7-f9dc-4147-96d3-d31f03164f9d"}}
_WD_FindElement ==> Webdriver Exception: HTTP status = 0
__WD_Post: URL=HTTP://127.0.0.1:9515/session/3760f251ffb2b0faf6cbbaaf666a02f4/element//value; $sData={"id":"", "text":"Smith"}
__WD_Post: StatusCode=0; ResponseText={"value":{"error":"no such element","message":"no such element: Element_id length is invalid\n  (Ses...
_WD_ElementAction: {"value":{"error":"no such element","message":"no such element: Element_id length is invalid\n  (Ses...
_WD_ElementAction ==> Webdriver Exception: {"value":{"error":"no such element","message":"no such element: Element_id length is invalid\n  (Session info: chrome=84.0.4147.89)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00EF87E3+2852835]\n\tOrdinal0 [0x00DE5BB1+1727409]\n\tOrdinal0 [0x00CBE4B9+517305]\n\tOrdinal0 [0x00C59610+103952]\n\tOrdinal0 [0x00C55F10+89872]\n\tOrdinal0 [0x00C6B85D+178269]\n\tOrdinal0 [0x00C542A6+82598]\n\tOrdinal0 [0x00C6BAA1+178849]\n\tOrdinal0 [0x00C74B9C+215964]\n\tOrdinal0 [0x00C6B70B+177931]\n\tOrdinal0 [0x00C52584+75140]\n\tOrdinal0 [0x00C53650+79440]\n\tOrdinal0 [0x00C535E9+79337]\n\tOrdinal0 [0x00DFAD5C+1813852]\n\tGetHandleVerifier [0x0101C616+1075574]\n\tGetHandleVerifier [0x0101C367+1074887]\n\tGetHandleVerifier [0x01027497+1120247]\n\tGetHandleVerifier [0x0101CC16+1077110]\n\tOrdinal0 [0x00DF3206+1782278]\n\tOrdinal0 [0x00DFC3BB+1819579]\n\tOrdinal0 [0x00DFC523+1819939]\n\tOrdinal0 [0x00E12B45+1911621]\n\tBaseThreadInitThunk [0x76C96359+25]\n\tRtlGetAppContainerNamedObjectPath [0x77D77C24+228]\n\tRtlGetAppContainerNamedObjectPath [0x77D77BF4+180]\n"}}
>Exit code: 0    Time: 11.29
 

image.png.2a9089754c81846f90c4a27e1604a61c.png

 

#include "wd_core.au3"
#include "wd_helper.au3"
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <GuiConstantsEx.au3>
#include <File.au3>
#include <GuiComboBox.au3>
#include <IE.au3>
#include <Chrome.au3>
#include <Json.au3>
Local $sDesiredCapabilities, $iIndex, $sSession
Setupchrome()
$_WD_DEBUG = $_WD_DEBUG_Info
_WD_Option('Driver', 'C:\Users\jiya\Desktop\AutoIT Script\chromedriver.exe')
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://omd.infomc.biz/iPC/Login.aspx?cmdLogout=true")
Sleep(2000)
;_WD_Navigate($sSession, "https://omd.infomc.biz/iPC/IncedoPC.aspx#PatientSearch")
Sleep(1000)
_ChromeSetInputValueById($sSession,'txtUserName','Smith')


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":["start-maximized", "disable-infobars"], "prefs": {"profile.default_content_setting_values.javascript": 2}}}}}'
EndFunc

Func _ChromeSetInputValueById($sSession,$Id,$Value)
 $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']")
 _WD_ElementAction($sSession,$sButton,'value', $Value)
EndFunc

 

 

Link to comment
Share on other sites

#include "wd_core.au3"
#include "wd_helper.au3"
#include <FileConstants.au3>
#include <WinAPIFiles.au3>
#include <GuiConstantsEx.au3>
#include <File.au3>
#include <GuiComboBox.au3>
#include <IE.au3>
#include <Chrome.au3>
#include <Json.au3>
#include <Excel.au3>

Local $sDesiredCapabilities, $iIndex, $sSession
Setupchrome()
_WD_Option('Driver', 'C:\Users\jiya\Desktop\AutoIT Script\chromedriver.exe')
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://omd.infomc.biz/iPC/Login.aspx?cmdLogout=true")
Sleep(2000)

Sleep(1000)
_ChromeSetInputValueById($sSession,'txtUserName','AvananOMHC')
_ChromeSetInputValueById($sSession,'txtPassword','Alan@123')
;$sButton1 = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@ID='lnkLogin']")
 ;   _WD_ElementAction($sSession, $sButton1, 'click')
  ;  _WD_LoadWait($sSession, 2000)
$sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//button[@id='lnkLogin']")
_WD_ElementAction($sSession, $sElement, 'click')
Sleep(500)
_WD_Navigate($sSession, "https://omd.infomc.biz/iPC/IncedoPC.aspx#PatientSearch")
Sleep(2000)
_ChromeSetInputValueById($sSession,'txtLast','Kraft')
_ChromeSetInputValueById($sSession,'txtFirst','Amy')
Sleep(500)
_ChromeSetInputValueById($sSession,'txtDOB','04/26/1961')
Send ("{TAB}")
Local $aSelect = _WD_ElementOptionSelect($sSession, $_WD_LOCATOR_ByXPath, "//select[@id='ddGender']/option[2]")
$sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//button[@id='tran1']")
_WD_ElementAction($sSession, $sElement, 'click')
Sleep(1000)
;$sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//tr@ID='1142349_M_0']")


local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//*[contains(text(),'patientGrid_Ext_ID')]")
       _ArrayDisplay($aElements, "Found Elements")
 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":["start-maximized"]}}}}'
EndFunc

Func _ChromeSetInputValueById($sSession,$Id,$Value)
 $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']")
 _WD_ElementAction($sSession,$sButton,'value', $Value)
EndFunc

image.thumb.png.de915486732a8d7ed36f43fbb15c6fe2.png

Link to comment
Share on other sites

@Guru_Ragavendra You've just posted your userID and password for the entire world to see. Suggest that you change your password immediately!

Edit: I changed your password, so you'll likely need to do a reset in order to regain access.

You may need to report this as a data breach since it appears that you've exposed a bunch of medical records on the web 😲🙄

Edited by Danp2
Link to comment
Share on other sites

25 minutes ago, Guru_Ragavendra said:

I am looking to obtain Title from this table, It is dynamically change based on input.

This xpath should give you the desired element in the table as long as you only need the top record and the table layout doesn't change --

//table[@id='patientGrid']//tr[2]/td[9]

 

Link to comment
Share on other sites

On 7/18/2020 at 7:49 AM, Aether said:

ssue 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

I ran into this issue under Windows Server 2016 and it seems that it is related to security protocols. You can review the Github issue here. If you have a chance, try commenting out that one line or remove the $WINHTTP_FLAG_SECURE_PROTOCOL_ALL and let me know if that resolves the issue under Windows 7.

Thanks, Dan

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