Jump to content

WebDriver UDF - Help & Support


Recommended Posts

@Danp2 Sorry, I know the problem.

What should I do when the code is hidden inside a frame?

_WD_GetSource: {"value":"\u003Chtml xmlns=\"http://www.w3.org/1999/xhtml\">\u003Chead>\n        \u003Cmeta charset=\"utf-8\" />\n        \u003Ctitle>????????? ????? ?8389\u003C/title>\n        \u003Clink rel=\"shortcut icon\" href=\"img/ico.ico\" />\n    \u003C/head>\n    \u003Cframeset rows=\"*,70\" style=\"border: none;\" frameborder=\"no\" framespacing=\"0\" border=\"0\">\n        \u003Cframe id=\"content_frame\" name=\"content_frame\" src=\"http://www.seosprint.net/?ref=11027427\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"0\" style=\"border: 0px;\" />\n        \u003Cframe id=\"counter_frame\" name=\"counter_frame\" src=\"visit_frame.php?id=8389\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\" noresize=\"noresize\" frameborder=\"0\" />\n    \u003C/frameset>\u003Cnoframes>\u003C/noframes>\n\n\u003C/html>"}

 

Edited by NguyenLe
Link to comment
Share on other sites

How could i get the web driver to navigate to a page but not wait for it to load, just move onto the next line of code?

I looked into __WD_Navigate within wd_core, which lead onto WinHttp.au3 but no matter what i can comment out It always seems to wait. I cant see any obvious loops that would keep the thread from returning. 

Setting _WinHttpSetTimeouts and _WD_Timeouts to 0 dont seem to help either. 

Edited by IanN1990
Link to comment
Share on other sites

1 hour ago, Danp2 said:

I believe this was covered previously in this thread. Try searching within it for the term pageLoadStrategy.

Thanks that was perfect :)

For anyone else who lands on this.

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args": ["--disable-infobars --kiosk"]},"pageLoadStrategy":"none"}}}'

is what i am now using.

Edited by IanN1990
Link to comment
Share on other sites

I would like to use a portable version of chrome with this UDF, however I'm failing to add the parameter to the capabilities. As an Error I get missing command parameters.

Here's the code within the SetupChrome function:

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

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c":true, "binary":"' & @ScriptDir & '\Chrome\App\Chrome-bin\chrome.exe"}}}}'
EndFunc

This is the Console Output:

Quote

--> Press Ctrl+Alt+Break to Restart or Ctrl+Break to Stop
_WDStartup: OS:    WIN_10 WIN32_NT 17134
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.1.0.16
_WDStartup: Driver:    C:\Users\m\Desktop\AutoitChromePortable\Chrome\chromedriver.exe
_WDStartup: Params:    --log-path="C:\Users\m\Desktop\AutoitChromePortable\chrome.log"
_WDStartup: Port:    9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c":true, "binary":"C:\Users\m\Desktop\AutoitChromePortable\Chrome\App\Chrome-bin\chrome.exe"}}}}
__WD_Post: StatusCode=400; ResponseText=missing command parameters
_WD_CreateSession: missing command parameters
_WD_CreateSession ==> Webdriver Exception
__WD_Delete: URL=HTTP://127.0.0.1:9515/session/
__WD_Delete: StatusCode=200; ResponseText={"sessionId":"","status":0,"value":null}
_WD_DeleteSession: {"sessionId":"","status":0,"value":null}
+>17:25:35 AutoIt3.exe ended.rc:0
+>17:25:35 AutoIt3Wrapper Finished.
>Exit code: 0    Time: 1.274

On the ChromeWebdriver Website i found the following option:

Quote

Using a Chrome executable in a non-standard location


ChromeOptions options = new ChromeOptions();
options.setBinary("/path/to/other/chrome/binary");

chromeOptions object

This is a list of all the Chrome-specific desired capabilities, which all are under the chromeOptions dictionary. 

If possible, use the ChromeOptions class instead of specifying these directly.
 
 Name Type Default  Description 
       
binary string    Path to the Chrome executable to use (on Mac OS X, this should be the actual binary, not just the app. e.g., '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome')

Thanks a lot!

 

Edited by crazycrash
Link to comment
Share on other sites

34 minutes ago, crazycrash said:

__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c":true, "binary":"C:\Users\m\Desktop\AutoitChromePortable\Chrome\App\Chrome-bin\chrome.exe"}}}}
__WD_Post: StatusCode=400; ResponseText=missing command parameters
_WD_CreateSession: missing command parameters

The issue is the backslash characters in the file path. Either replace them with forward slashes or "escape" them with another backslash.

Link to comment
Share on other sites

Thank a ton! Also @ScriptDir needs to be changed if anyone else has the same problem! Cheers

This worked:

Func SetupChrome()
;MsgBox(0,"",@ScriptDir & '/Chrome/chromedriver.exe')
_WD_Option('Driver', @ScriptDir & '/Chrome/chromedriver.exe')
_WD_Option('Port', 9515)
_WD_Option('DriverParams', '--log-path="' & @ScriptDir & '/chrome.log"')

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c":true, "binary":"' & StringReplace (@ScriptDir, "\", "/") & '/Chrome/App/Chrome-bin/chrome.exe"}}}}'
EndFunc

 

Edited by crazycrash
Link to comment
Share on other sites

1 hour ago, Deathdn said:

How to I get handle of the window open by Webdriver?

You could use _WD_Action($sSession, 'title') to get the document title for the active tab. You should then be able to use one of the standard Autoit commands to get the window's handle by the title.

Quote

I need handle for WinSetState() like 0x00020990. 

Why? There may be a better way to accomplish your goal. Please tell us which browser you are using and how you intend to use WinSetState to manipulate the window's state.

Link to comment
Share on other sites

Hi friends,

I'm trying to get the element from a chrome session using _WD_GetElementFromPoint. But when the element is on an iframe , I always get a blank element id.

When I am on the session, I get the iframe element id and tag but after entering into the frame, I always get blank values.

Is there any thing else that I need to take care when I'm trying to get an element , which is in an iframe using  _WD_GetElementFromPoint? Please help.

Func DemoFrames()
    _WD_Navigate($sSession, "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_frame_cols")
    ConsoleWrite("***Number of frames=" & _WD_GetFrameCount($sSession) & @CRLF)
    While (1)
        $sElement = _WD_GetElementFromPoint($sSession, 720,290)
        $sTag = _WD_ElementAction($sSession, $sElement, 'name')
        ConsoleWrite("***Element = " & $sElement & ", Tag: " & $sTag & @CRLF)
        If StringInStr($sTag,"iframe") = 0 or $sElement = "" Then ExitLoop ;if not an iframe
        $sResult =  _WD_FrameEnter($sSession, $sElement)
        ConsoleWrite("*** Frame enter Result = " & $sResult & @CRLF)
    wend
    While not _WD_IsWindowTop($sSession)
        _WD_FrameLeave($sSession)
    Wend

    #cs

    ;ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='iframeResult']")
    _WD_FrameEnter($sSession, $sElement)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)
    _WD_FrameLeave($sSession)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)
    #ce

EndFunc

 

 

Link to comment
Share on other sites

2 hours ago, PoojaKrishna said:

I'm trying to get the element from a chrome session using _WD_GetElementFromPoint. But when the element is on an iframe , I always get a blank element id.

_WD_GetElementFromPoint isn't designed to work with frames. When I have a chance, I'll see if there's a way to make it compatible with frames.

Link to comment
Share on other sites

  • 2 weeks later...

HI,

does somebody has trouble with Func _WD_NewTab?

If i start a session and my FF window the first tab is automatically opened. This is ok.

If i excute the Func _WD_NewTab(), a new Tab will be opend. This is ok.

From this on i can open as many tabs as i want. This is ok.

But if i close the first Tab, which was opend by the Func _WD_NewTab(), then Func does not work anymore.

Does somebody had the error as me?

I use the easy command

_WD_NewTab($sSession)
_WD_Navigate($sSession, 'https://duckduckgo.com/')
_WD_NewTab ==> Webdriver Exception
__WD_Post: URL=HTTP://127.0.0.1:4444/session/0ae9bf11-0fe6-4ab0-b7aa-dae67af54df9/url; $sData={"url":"https://duckduckgo.com/"}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such window","message":"Browsing context has been discarded","stacktrace":"WebDriverError@chrome://marionette/content/error.js:178:5\nNoSuchWindowError@chrome://marionette/content/error.js:410:5\nassert.that/<@chrome://marionette/content/assert.js:401:13\nassert.open@chrome://marionette/content/assert.js:157:10\nGeckoDriver.prototype.get@chrome://marionette/content/driver.js:1060:3\ndespatch@chrome://marionette/content/server.js:291:20\nexecute@chrome://marionette/content/server.js:264:11\nonPacket/<@chrome://marionette/content/server.js:237:15\nonPacket@chrome://marionette/content/server.js:236:8\n_onJSONObjectReady/<@chrome://marionette/content/transport.js:490:9\n"}}

Best regards,

horphi

Link to comment
Share on other sites

No problem...

You need to modify "_WD_Option('Driver', 'D:\YOUR_LOCAL_PATH\geckodriver-v0.23.0-win64\geckodriver.exe  "--marionette-port 2828"')"

  1. Open the session
  2. Klick DDG Suche
  3. Close the Tab and click again....

BR

Horphi

#include <MsgBoxConstants.au3>
#include <Array.au3>
#include "wd_core.au3"
#include "wd_helper.au3"
#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <FileConstants.au3>
#include <File.au3>
#include <Misc.au3>
#include <GuiListBox.au3>
#include <EditConstants.au3>
#include <Clipboard.au3>
#include <MsgBoxConstants.au3>
#include <Date.au3>

;~ #RequireAdmin ;Will give your script a permission elevation (sometimes its needed)
;~ Opt("WinTitleMatchMode", 4) ;1=start, 2=subStr, 3=exact, 4=advanced, -1 to -4=Nocase
;~ Opt("WinSearchChildren", 1) ;0=no, 1=search children also

Local $hDLL = DllOpen("user32.dll")
Local Enum $eFireFox = 0, $eChrome
Local Const $_TestType = $eFireFox
Local $sDesiredCapabilities = '{}'
Local $sSession
Local $sURL = 'https://duckduckgo.com/'

;~ $_WD_DEBUG = False
$_WD_DEBUG = True


#Region ### START Koda GUI section ###
$hGUI = GUICreate("Form1", 400, 300, 991, 141, BitOR($GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX, $WS_THICKFRAME, $WS_TABSTOP))
$MenuItem2 = GUICtrlCreateMenu("&File")
$MenuItem6 = GUICtrlCreateMenuItem("Open Textfile", $MenuItem2)
$MenuItem4 = GUICtrlCreateMenuItem("Open Session", $MenuItem2)
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem2)
$MenuItem7 = GUICtrlCreateMenu("&User Settings")
$MenuItem11 = GUICtrlCreateMenuItem("Login credentials", $MenuItem7)
$opsess = GUICtrlCreateButton("Open Session", 32, 19, 105, 33)
$newTab = GUICtrlCreateButton("DDG Suche", 32, 59, 105, 33)
GUICtrlSetResizing($opsess, $GUI_DOCKALL)
GUICtrlSetResizing($newTab, $GUI_DOCKALL)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            _endSession()
            Exit
        Case $opsess
            SetupGecko()
            _startSession()
        Case $newTab
            _newTab()
    EndSwitch
WEnd

Switch $_TestType
    Case $eFireFox
        SetupGecko()

;~  Case $eChrome
;~      SetupChrome()

EndSwitch

Func _newTab() ;--> neues Tabfenster erstellen und Adresse eingeben
    Local $sSearch = 0
    $sSelListDDG = 0
    _WD_NewTab($sSession)
    _WD_Navigate($sSession, 'https://duckduckgo.com/?q=' & $sSelListDDG & '&t=ffab&iar=images&iax=images&ia=images')
EndFunc   ;==>_newTab

Func _endSession()
    If $sSession <> '' Then
        _WD_DeleteSession($sSession)
        _WD_Shutdown()
    EndIf
EndFunc   ;==>_endSession


#Region ### SUpport Functions only ###

Func _IsChecked($idControlID)
    Return BitAND(GUICtrlRead($idControlID), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>_IsChecked


Func _startSession()
    _WD_Startup()
    $sSession = _WD_CreateSession($sDesiredCapabilities)
    $inav = _WD_Navigate($sSession, $sURL)
    Sleep(2000)
EndFunc   ;==>_startSession

Func SetupGecko()
    $sDesiredCapabilities = '{"desiredcapabilities":{"javascriptEnabled":false,"nativeEvents":true,"acceptInsecureCerts":true}}'
    _WD_Option('Driver', 'D:\YOUR_LOCAL_PATH\geckodriver-v0.23.0-win64\geckodriver.exe  "--marionette-port 2828"')
    _WD_Option('DriverParams', '--log trace')
    _WD_Option('Port', 4444)
EndFunc   ;==>SetupGecko

Func _ArrayRemoveBlanks($aID)
    Local $sTmp = ''
    For $i = 0 To UBound($aID) - 1
        If StringRegExpReplace($aID[$i], "\s", "") Then $sTmp &= $aID[$i] & Chr(0)
    Next
    Return StringSplit(StringTrimRight($sTmp, 1), Chr(0))
EndFunc   ;==>_ArrayRemoveBlanks

Func _GetText()
    Local $PrevClip = ClipGet()
    Send('^c')
;~  ConsoleWrite(ClipGet() & @LF)
EndFunc   ;==>_GetText

#EndRegion ### SUpport Functions only ###

 

Edited by horphi
Link to comment
Share on other sites

@horphi Here's a revised version of _WD_NewTab. Please review the code for any oversights on my part and then test to ensure it works as expected.

Func _WD_NewTab($sSession, $lSwitch = True, $iTimeout = -1)
    Local Const $sFuncName = "_WD_NewTab"
    Local $sTabHandle = '', $sLastTabHandle, $hWaitTimer, $iTabIndex, $aTemp

    If $iTimeout = -1 Then $iTimeout = $_WD_DefaultTimeout

    Local $aHandles = _WD_Window($sSession, 'handles')

    If @error <> $_WD_ERROR_Success Or Not IsArray($aHandles) Then
        Return SetError(__WD_Error($sFuncName, $_WD_ERROR_Exception), 0, $sTabHandle)
    EndIf

    $iTabCount = UBound($aHandles)

    ; Get handle to current last tab
    $sLastTabHandle = $aHandles[$iTabCount - 1]

    ; Get handle for current tab
    Local $sCurrentTabHandle = _WD_Window($sSession, 'window')

    If @error = $_WD_ERROR_Success Then
        ; Search for current tab handle in array of tab handles. If not found,
        ; then make the current tab handle equal to the last tab
        $iTabIndex = _ArraySearch($aHandles, $sCurrentTabHandle)

        If @error Then
            $sCurrentTabHandle = $sLastTabHandle
            $iTabIndex = $iTabCount - 1
        EndIf
    Else
        _WD_Window($sSession, 'Switch', '{"handle":"' & $sLastTabHandle & '"}')
        $sCurrentTabHandle = $sLastTabHandle
        $iTabIndex = $iTabCount - 1
    EndIf


    _WD_ExecuteScript($sSession, 'window.open()', '{}')

    If @error <> $_WD_ERROR_Success Then
        Return SetError(__WD_Error($sFuncName, $_WD_ERROR_Exception), 0, $sTabHandle)
    EndIf

    $hWaitTimer = TimerInit()

    While 1
        $aTemp = _WD_Window($sSession, 'handles')

        If UBound($aTemp) > $iTabCount Then
            $sTabHandle = $aTemp[$iTabIndex + 1]
            ExitLoop
        EndIf

        If TimerDiff($hWaitTimer) > $iTimeout Then Return SetError(__WD_Error($sFuncName, $_WD_ERROR_Timeout), 0, $sTabHandle)

        Sleep(10)
    WEnd

    If $lSwitch Then
        _WD_Window($sSession, 'Switch', '{"handle":"' & $sTabHandle & '"}')
    Else
        _WD_Window($sSession, 'Switch', '{"handle":"' & $sCurrentTabHandle & '"}')
    EndIf

    Return SetError($_WD_ERROR_Success, 0, $sTabHandle)
EndFunc

 

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...