Jump to content

WebDriver UDF (W3C compliant version) - 2024/09/21


Danp2
 Share

Recommended Posts

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

Local $sDesiredCapabilities, $sSession

SetupGecko()

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://soap2day.im/")

Func SetupGecko()
_WD_Option('Driver', 'geckodriver.exe')
_WD_Option('DriverParams', '--log trace')
_WD_Option('Port', 4444)
$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"browserName": "firefox", "acceptInsecureCerts":true}}}'
EndFunc

I want view  https://soap2day.im using webdriver but cloudflare has blocked.

Link to comment
Share on other sites

Question:

Is there a trick to acquiring pre-click elements or pre-keypress elements.

For example if I connect to my webserver which changes html data frequently and I manually type in a value to search for and press enter, it seems $LastFieldVal = _WD_ElementAction($sSession, $LastClickMelem, 'attribute', 'value') is gone instantly after pressing Enter.  The value in the field is not accurate after the Enter key is pressed or a submit button is clicked.

Edited by NassauSky
Link to comment
Share on other sites

@Danp2 Hmmm come to think of it I might not need to do it that way. Generally it's just me running the tests so I can do it myself.  Trying to make my life easier collecting a vast amount of statistics and while I was working on the project I was thinking to make it future usable for a broader spectrum of options. 

Thanks for being quick with your responses. It was a holiday.

Edited by NassauSky
Link to comment
Share on other sites

DEAR @Danp2

i have opened Telnet and i Attached with exist web page .

my case is i could not put a value to text and click the button .

i have use many ways but not working 

 

SetupChrome()
_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)
MsgBox(0,'$sSession',$sSession)
;_WD_Navigate($sSession, "https://vpn.saudia.com:11029/1ASIHGAPSV/arp/index.html?SITK=QQC5RKM89J000203FNCAYXNE0002&SITK2=QQC5RKM89J000203FNCAYXNE0002&SYS=PRODUCTION&PHS=PRD")
_WD_Attach  ($sSession,"Amadeus Retailing Platform - PRD(PRODUCTION)",DefaulT)
SendElements("//input[@name=aFSearchParameter]",'056')
;SendElements("//input[ name='aFSearchParameter']",'056')
;SendElements("//input[@ID='txtPassword']",'sami')
MsgBox(0,0,'stop')
;;DemoClick("//button[@ID='btnSearchId']")
;;MsgBox(0,1,'stop')
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": {"debuggerAddress": "localhost:9222"}}}}'
EndFunc
Func SendElements($Elment,$TXT)
    Local $sElement, $aElements, $sValue, $sButton, $sResponse, $bDecode, $sDecode, $hFileOpen

    ;***********************************************************************
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, $Elment)
    MsgBox(0,$TXT,$sElement)
  ;***********************************************************************
    Local $TKT_ID = _WD_GetElementByName($sSession, 'aFSearchParameter')
    MsgBox(0,'$TKT_ID',$TKT_ID)
  ;***********************************************************************
    $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iput", Default)
    _ArrayDisplay($aElements, "Found Elements")
  ;***********************************************************************
for $i = 0 to UBound($aElements)-1
     $sValue = _WD_ElementAction($sSession, StringStripWS($aElements[$i],8),'NAME')
    MsgBox(0,'Name',$sValue)
Next
;***********************************************************************
    $sValue = _WD_ElementAction($sSession, $sElement, 'property', 'value')
    _WD_ElementAction($sSession, $sElement, 'clear')
    ; Set element's contents
    ;MsgBox(0,'Send user',$TXT)
    _WD_ElementAction($sSession, $sElement, 'value', $TXT)


;MsgBox(0,'send done',$sElement)
    ; Retrieve then clear contents

EndFunc

 

Screenshot_3.png

Link to comment
Share on other sites

@samibb Telling me that something doesn't work without any further details isn't very helpful. 😒

Run this code in Scite and then post the resulting output --

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

Local $sDesiredCapabilities, $sSession, $sElement

SetupChrome()
_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Attach($sSession,"Amadeus Retailing Platform - PRD(PRODUCTION)",DefaulT)

$sElement = _WD_GetElementByName($sSession, 'aFSearchParameter')

If Not @error Then
    _WD_SetElementValue($sSession, $sElement, '056')
EndIf


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": {"debuggerAddress": "localhost:9222"}}}}'
EndFunc

 

Link to comment
Share on other sites

@Danp2

good day

>"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\11003813\Desktop\AutoIT\xxx111.au3" /UserParams    
+>07:31:24 Starting AutoIt3Wrapper v.16.612.1119.0 SciTE v.3.6.6.0   Keyboard:00000409  OS:WIN_81/  CPU:X64 OS:X64  Environment(Language:0409)  CodePage:0  utf8.auto.check:4
+>         SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE   UserDir => C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper
>Running AU3Check (3.3.14.2)  from:C:\Program Files (x86)\AutoIt3  input:C:\Users\11003813\Desktop\AutoIT\xxx111.au3
+>07:31:24 AU3Check ended.rc:0
>Running:(3.3.14.2):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\11003813\Desktop\AutoIT\xxx111.au3"    
--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
_WD_IsLatestRelease: True
_WD_IsLatestRelease ==> Success
_WDStartup: OS: WIN_81 WIN32_NT 9600 
_WDStartup: AutoIt: 3.3.14.2
_WDStartup: WD.au3: 0.3.1.0 (Up to date)
_WDStartup: WinHTTP:    1.6.4.2
_WDStartup: Driver: chromedriver.exe
_WDStartup: Params: --verbose --log-path="C:\Users\11003813\Desktop\AutoIT\chrome.log"
_WDStartup: Port:   9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"debuggerAddress": "localhost:9222"}}}}
__WD_Post: StatusCode=200; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"86.0....
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"86.0.4240.198","chrome":{"chromedriverVersion":"86.0.4240.22 (398b0743353ff36fb1b82468f63a3a93b4e2e89e-refs/branch-heads/4240@{#378})"},"goog:chromeOptions":{"debuggerAddress":"localhost:9222"},"pageLoadStrategy":"normal","platformName":"","proxy":{},"setWindowRect":false,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:virtualAuthenticators":true},"sessionId":"15283bdd9a40c0b5b227acb9a5e3b2ce"}}
__WD_Get: URL=HTTP://127.0.0.1:9515/session/15283bdd9a40c0b5b227acb9a5e3b2ce/window/handles
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":["CDwindow-35DB90B648DE5F59F606CC6BABB831FF","CDwindow-4797BE00D12B8E0B5702AC417283A770","C...
_WD_Window: {"value":["CDwindow-35DB90B648DE5F59F606CC6BABB831FF","CDwindow-4797BE00D12B8E0B5702AC417283A770","C...
__WD_Get: URL=HTTP://127.0.0.1:9515/session/15283bdd9a40c0b5b227acb9a5e3b2ce/window
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"CDwindow-35DB90B648DE5F59F606CC6BABB831FF"}...
_WD_Window: {"value":"CDwindow-35DB90B648DE5F59F606CC6BABB831FF"}...
__WD_Post: URL=HTTP://127.0.0.1:9515/session/15283bdd9a40c0b5b227acb9a5e3b2ce/window; $sData={"handle":"CDwindow-35DB90B648DE5F59F606CC6BABB831FF"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_Window: {"value":null}...
__WD_Get: URL=HTTP://127.0.0.1:9515/session/15283bdd9a40c0b5b227acb9a5e3b2ce/title
__WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"Amadeus Retailing Platform - PRD(PRODUCTION)"}...
_WD_Action: {"value":"Amadeus Retailing Platform - PRD(PRODUCTION)"}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/15283bdd9a40c0b5b227acb9a5e3b2ce/element; $sData={"using":"xpath","value":"//*[@name=\"aFSearchParameter\"]"}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\...
__WD_Post ==> No match: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//*[@name=\"aFSearchParameter\"]\"}\n  (Session info: chrome=86.0.4240.198)","stacktrace":"Backtrace:\n\tOrdinal0 [0x003EC013+3194899]\n\tOrdinal0 [0x002D6021+2056225]\n\tOrdinal0 [0x0016F608+587272]\n\tOrdinal0 [0x000FB5A1+112033]\n\tOrdinal0 [0x0011B182+242050]\n\tOrdinal0 [0x0010FDAA+196010]\n\tOrdinal0 [0x00119B22+236322]\n\tOrdinal0 [0x0010FC1B+195611]\n\tOrdinal0 [0x000F3B7F+80767]\n\tOrdinal0 [0x000F4B4E+84814]\n\tOrdinal0 [0x000F4AD9+84697]\n\tOrdinal0 [0x002ECE64+2149988]\n\tGetHandleVerifier [0x0055BE95+1400773]\n\tGetHandleVerifier [0x0055BB61+1399953]\n\tGetHandleVerifier [0x005631FA+1430314]\n\tGetHandleVerifier [0x0055C69F+1402831]\n\tOrdinal0 [0x002E3D61+2112865]\n\tOrdinal0 [0x002EE5CB+2155979]\n\tOrdinal0 [0x002EE6F5+2156277]\n\tOrdinal0 [0x002FF26E+2224750]\n\tBaseThreadInitThunk [0x775F495D+14]\n\tRtlInitializeExceptionChain [0x779B98EE+132]\n\tRtlInitializeExceptionChain [0x779B98C4+90]\n\t(No symbol) [0x00000000]\n"}}
_WD_FindElement: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//*[@name=\"aFSearchParameter\"]\"}\n  (Session info: chrome=86.0.4240.198)","stacktrace":"Backtrace:\n\tOrdinal0 [0x003EC013+3194899]\n\tOrdinal0 [0x002D6021+2056225]\n\tOrdinal0 [0x0016F608+587272]\n\tOrdinal0 [0x000FB5A1+112033]\n\tOrdinal0 [0x0011B182+242050]\n\tOrdinal0 [0x0010FDAA+196010]\n\tOrdinal0 [0x00119B22+236322]\n\tOrdinal0 [0x0010FC1B+195611]\n\tOrdinal0 [0x000F3B7F+80767]\n\tOrdinal0 [0x000F4B4E+84814]\n\tOrdinal0 [0x000F4AD9+84697]\n\tOrdinal0 [0x002ECE64+2149988]\n\tGetHandleVerifier [0x0055BE95+1400773]\n\tGetHandleVerifier [0x0055BB61+1399953]\n\tGetHandleVerifier [0x005631FA+1430314]\n\tGetHandleVerifier [0x0055C69F+1402831]\n\tOrdinal0 [0x002E3D61+2112865]\n\tOrdinal0 [0x002EE5CB+2155979]\n\tOrdinal0 [0x002EE6F5+2156277]\n\tOrdinal0 [0x002FF26E+2224750]\n\tBaseThreadInitThunk [0x775F495D+14]\n\tRtlInitializeExceptionChain [0x779B98EE+132]\n\tRtlInitializeExceptionChain [0x779B98C4+90]\n\t(No symbol) [0x00000000]\n"}}
_WD_FindElement ==> No match: HTTP status = 404
_WD_GetElementByName ==> No match
+>07:31:30 AutoIt3.exe ended.rc:0
+>07:31:30 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 6.247

Thanks

Link to comment
Share on other sites

@Danp2

when i use "//div" ,i get 35 elements . only labels, no text or button .

see as you see in the image down  

 Have you ruled out frames? No, how please?

$aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div", Default, True)
    _ArrayDisplay($aElements, "Found Elements")

    ;msgBox(0,'clear',$sElement)
    for $i = 0 to UBound($aElements) - 1
      ;$sElement = "txtUsername"
      $sValue = _WD_ElementAction($sSession, $aElements[$i], 'text')
      MsgBox(0,$aElements[$i],$sValue)
    Next

image.thumb.png.1fdf0f8ededa6d5a3fdf89eaf48b2138.png

Edited by samibb
Link to comment
Share on other sites

  • 3 weeks later...

I have a problem with the RAM.
When the program runs Chrome, Chrome will gradually use the entire RAM until it stops and gives me this message :

Aw, Snap. Something went wrong while displaying this webpage

Error :Out of memory


How is it possible to free up memory and make Chrome to continue running ?

Link to comment
Share on other sites

1 hour ago, DreamMaker said:

 Is it similar to _IEBodyReadText()?

Untested, but you should be able to do something like this --

_WD_ExecuteScript($sSession, "return document.body.innerText;", '{}')

P.S. Next time, please use Google Translate and post your message in English instead of Chinese. 🙂

Link to comment
Share on other sites

  • Danp2 changed the title to WebDriver UDF (W3C compliant version) - 2024/09/21
  • 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...