Jump to content

Click a Link In Chrome?


Recommended Posts

5 minutes ago, kornholeking said:

Is there a difference between using $sCapabilities and $sDesiredCapabilities?

No, simply older vs current terminology.

Your code looks ok. I would suggest not changing $_WD_DEBUG until you've figured things out further.

FYI, you should review this post for the proper way to post code on the forum.

Link to comment
Share on other sites

Sorry about that - I've actually updated WD debug to FULL. Does this help? The rest of the script remains the same and now the console is showing the following:

>Running:(3.3.16.0):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\temp\AutoIT\test.au3"    
+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
_WD_CapabilitiesStartup: #148 : > {"capabilities":"{}"} > IsObj = 1
_WD_CapabilitiesAdd: #177 :      $key = alwaysMatch     $value1 = chrome     $value2 = 
_WD_CapabilitiesAdd: #205 :  $_WD_NOTATION__MATCHTYPE = [capabilities][alwaysMatch] $_WD_NOTATION__SPECIFICVENDOR = ["goog:chromeOptions"]
_WD_CapabilitiesAdd ==> Success (0) : Successfully used [alwaysMatch]  with specified browser: chrome
_WD_CapabilitiesAdd: #177 :      $key = w3c     $value1 = True     $value2 = 
_WD_CapabilitiesAdd: #257 #273 :      $key = w3c     $value1 = True     $value2 =     $s_Notation = [capabilities][alwaysMatch]["goog:chromeOptions"][w3c]   <<<<  True
_WD_CapabilitiesAdd ==> Success (0) : Successfully added capability
_WD_CapabilitiesAdd: #177 :      $key = excludeSwitches     $value1 = enable-automation     $value2 = 
_WD_CapabilitiesAdd: #239 #273 :      $key = excludeSwitches     $value1 = enable-automation     $value2 =     $s_Notation = [capabilities][alwaysMatch]["goog:chromeOptions"][excludeSwitches][0]   <<<<  enable-automation
_WD_CapabilitiesAdd ==> Success (0) : Successfully added capability
_WD_IsLatestRelease ==> Success (0) : True
_WD_Startup: OS:    WIN_10 WIN32_NT 18363 
_WD_Startup: AutoIt:    3.3.16.0
_WD_Startup: Webdriver UDF: 0.9.0 (Up to date)
_WD_Startup: WinHTTP:   1.6.4.2
_WD_Startup: Driver:    chromedriver.exe (32 Bit)
_WD_Startup: Params:    
_WD_Startup: Port:  9515
_WD_Startup: Command:   "chromedriver.exe"  
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={
    "capabilities":{
        "alwaysMatch":{
            "goog:chromeOptions":{
                "w3c":true,
                "excludeSwitches":[
                    "enable-automation"
                ]
            }
        }
    }
}
__WD_Post ==> Success (0) HTTP status = 200 : ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"101.0...
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"101.0.4951.54","chrome":{"chromedriverVersion":"100.0.4896.60 (6a5d10861ce8de5fce22564658033b43cb7de047-refs/branch-heads/4896@{#875})","userDataDir":"C:\\Users\\opena\\AppData\\Local\\Temp\\scoped_dir16152_1174674708"},"goog:chromeOptions":{"debuggerAddress":"localhost:62062"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify","webauthn:extension:credBlob":true,"webauthn:extension:largeBlob":true,"webauthn:virtualAuthenticators":true},"sessionId":"2f934a0d0d4ccad92302af1cf1e0ccc8"}}
_WD_CreateSession ==> Success (0) HTTP status = 200
__WD_Post: URL=HTTP://127.0.0.1:9515/session/2f934a0d0d4ccad92302af1cf1e0ccc8/url; $sData={"url":"www.google.com"}
__WD_Post ==> Invalid argument (5) HTTP status = 400 : ResponseText={"value":{"error":"invalid argument","message":"invalid argument\n  (Session info: chrome=101.0.4951...
_WD_Navigate ==> Invalid argument (5) HTTP status = 400 : {"value":{"error":"invalid argument","message":"invalid argument\n  (Session info: chrome=101.0.4951.54)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00517413+2389011]\n\tOrdinal0 [0x004A9F61+1941345]\n\tOrdinal0 [0x0039C520+836896]\n\tOrdinal0 [0x0038E019+778265]\n\tOrdinal0 [0x0038CB9F+773023]\n\tOrdinal0 [0x0038CE6D+773741]\n\tOrdinal0 [0x0039DE5A+843354]\n\tOrdinal0 [0x003F49BD+1198525]\n\tOrdinal0 [0x003E414C+1130828]\n\tOrdinal0 [0x003F4302+1196802]\n\tOrdinal0 [0x003E3F66+1130342]\n\tOrdinal0 [0x003BE546+976198]\n\tOrdinal0 [0x003BF456+980054]\n\tGetHandleVerifier [0x006C9632+1727522]\n\tGetHandleVerifier [0x0077BA4D+2457661]\n\tGetHandleVerifier [0x005AEB81+569713]\n\tGetHandleVerifier [0x005ADD76+566118]\n\tOrdinal0 [0x004B0B2B+1968939]\n\tOrdinal0 [0x004B5988+1989000]\n\tOrdinal0 [0x004B5A75+1989237]\n\tOrdinal0 [0x004BECB1+2026673]\n\tBaseThreadInitThunk [0x76706359+25]\n\tRtlGetAppContainerNamedObjectPath [0x776287D4+228]\n\tRtlGetAppContainerNamedObjectPath [0x776287A4+180]\n"}}
+>13:32:51 AutoIt3.exe ended.rc:0
+>13:32:51 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 14.28

Any further insight?

Link to comment
Share on other sites

@Danp2

That was literally it (lol). I've been exploring and testing the remainder of the afternoon and I believe I've got a script that works that does what I need (basically a few mouse clicks on some text links or Xpaths and input a text value.)

I may have some more questions as I continue to stumble my way through each step in the process I am attempting to achieve. Shall I continue to post on this topic or create new ones as I run into them?

 

In either case, thank you, again, for bearing with and helping me with the basics. Have a great weekend!

Link to comment
Share on other sites

So, I had, what I consider, a pretty simple script that was working as of my last post. However, now it seems that WD_Startup cannot find my chromedriver for some reason? I have not changed anything since this was working, so I'm not sure what has happened.

Script:

_WD_CapabilitiesStartup()
_WD_CapabilitiesAdd("alwaysMatch", "chrome")
_WD_CapabilitiesAdd("w3c", True)
_WD_CapabilitiesAdd("excludeSwitches", "enable-automation")
Local $sCapabilities = _WD_CapabilitiesGet()

_WD_Option('Driver', 'chromedriver.exe')
_WD_Option('Port', 9515)

Console:

+>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop.
_WD_CapabilitiesAdd ==> Success (0) : Successfully used [alwaysMatch]  with specified browser: chrome
_WD_CapabilitiesAdd ==> Success (0) : Successfully added capability
_WD_CapabilitiesAdd ==> Success (0) : Successfully added capability
_WD_Startup ==> File issue (18) : Non-existent Web Driver: chromedriver.exe

Any ideas??

Link to comment
Share on other sites

  • 2 weeks later...

@Danp2 I have a few questions on using the WD_Screenshot function regarding my Chrome session. I would assume that by simply putting _WD_Screenshot($sSession) that it would screenshot my Chrome window, is this correct? If so, how exactly am I able to do anything with the screenshot once taken or even be able to tell if a screenshot has been successfully taken? If not, then what does that function actually do?

Link to comment
Share on other sites

Okay, so, back to my question: I have the function _WD_Screenshot($sSession, $sElement). How exactly am I able to do anything with the screenshot once taken or even be able to tell if a screenshot has been successfully taken? Ideally, I'm trying to paste the screenshot into a document or email.

Link to comment
Share on other sites

This code is from wd_demo --

; Take element screenshot
    $sResponse = _WD_ElementAction($sSession, $sElement, 'screenshot')
    $bDecode = __WD_Base64Decode($sResponse)

    $hFileOpen = FileOpen("Element.png", $FO_BINARY + $FO_OVERWRITE)
    FileWrite($hFileOpen, $bDecode)
    FileClose($hFileOpen)

_WD_Screenshot performs the decoding for you, so the follow should be the equivalent using _WD_Screenshot --

; Take element screenshot
    $bImage = _WD_Screenshot($sSession, $sElement, 2) ; 2 = binary format
    
    If $iErr = $_WD_ERROR_Success Then
       $hFileOpen = FileOpen("Element.png", $FO_BINARY + $FO_OVERWRITE)
       FileWrite($hFileOpen, $bImage)
       FileClose($hFileOpen)
    EndIf

As far as placing the image on the clipboard, you may want to check out _ClipBoard_SetData.

Link to comment
Share on other sites

  • 2 weeks later...

I'm not familiar with ClipBoard functions. Are they from a custom UDF? If so, where can I find it?

I tried searching the forum for various clipboard keywords and functions, but couldn't find any UDFs with the _ClipBoard_SetData function you mentioned.

Link to comment
Share on other sites

Ok, awesome! So, now I've got the following:

; Take screenshot
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/form")
$bImage = _WD_Screenshot($sSession, $sElement, 2)

_ClipBoard_SetData($bImage)

I guess now I would need to convert the binary data before being able to paste the image or something? Is there a single function for doing the converting and pasting, or how can I accomplish this step?

Also, can _WD_Screenshot create image formats other than png? Can that be defaulted somewhere to a different image type?

Link to comment
Share on other sites

Not sure how you would properly place it on the clipboard. I imagine that at the minimum you will need to supply the optional 2nd parameter to _ClipBoard_SetData.

The file format can't be overridden, but you can convert the image into a different format following the screenshot. Maybe one of the members with lots of GDIPlus experience will see this and share some ideas.

Link to comment
Share on other sites

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

  • Recently Browsing   0 members

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