Jump to content
Danp2

WebDriver UDF (W3C compliant version) - 10/28/2020

Recommended Posts

11 minutes ago, NguyenLe said:

I can not use the Click Element command in Firefox

That's not the issue. 

11 minutes ago, NguyenLe said:

__WD_Post: URL=HTTP://127.0.0.1:4444/session/72ea7fca-2466-46cb-a334-5dbd8cdc7dba/element; $sData={"using":"xpath","value":"//a[@class='gsfi']"} __WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"Unable to locate element: //a[@class='gsfi']","stacktrace":"stack backtrace:\n   0:           0x4821c4 - <no info>\n   1:           0x482933 - <no info>\n   2:           0x445159 - <no info>\n   3:           0x44eff6 - <no info>\n   4:           0x4322e1 - <no info>\n   5:           0x40ba4e - <no info>\n   6:           0x4119b9 - <no info>\n   7:           0x6d2c89 - <no info>\n   8:           0x426006 - <no info>\n   9:           0x6cd490 - <no info>\n  10:         0x77a75a4d - BaseThreadInitThunk"}} _WD_FindElement: {"value":{"error":"no such element","message":"Unable to locate element: //a[@class='gsfi']","stacktrace":"stack backtrace:\n   0:           0x4821c4 - <no info>\n   1:           0x482933 - <no info>\n   2:           0x445159 - <no info>\n   3:           0x44eff6 - <no info>\n   4:           0x4322e1 - <no info>\n   5:           0x40ba4e - <no info>\n   6:           0x4119b9 - <no info>\n   7:           0x6d2c89 - <no info>\n   8:           0x426006 - <no info>\n   9:           0x6cd490 - <no info>\n  10:         0x77a75a4d - BaseThreadInitThunk"}} _WD_FindElement ==> No match: no such element

You can't click an element that wasn't found by the prior function call. You'll need to locate the element first. Also some error checking in your code would help you here as well.

Share this post


Link to post
Share on other sites
6 hours ago, Danp2 said:

That's not the issue. 

You can't click an element that wasn't found by the prior function call. You'll need to locate the element first. Also some error checking in your code would help you here as well.

Can you give me an example?

Share this post


Link to post
Share on other sites

@NguyenLe Just check @error after the function call, like this --

SetupGecko()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, 'http://google.com')
$sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//a[@class='gsfi']")

If @error = $_WD_ERROR_Success Then
    _WD_ElementAction($sSession, $sElement, 'value','Hello')
EndIf

 

Share this post


Link to post
Share on other sites
10 hours ago, Danp2 said:

@NguyenLe Just check @error after the function call, like this --

SetupGecko()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, 'http://google.com')
$sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//a[@class='gsfi']")

If @error = $_WD_ERROR_Success Then
    _WD_ElementAction($sSession, $sElement, 'value','Hello')
EndIf

 

I found the error.

Thank for your answer.

Edited by NguyenLe

Share this post


Link to post
Share on other sites

I've done a quick attempt to use this stuff with IE11 on Win7 and at first glance it seems to work.
I've only tryed to adapt the simple test from post #2 to be used with IE.
more infos here https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver
steps to do the test
1) Download the IEDriverServer.exe from here  http://selenium-release.storage.googleapis.com/index.html?path=3.8/ and save it along with the other scripts
2) open IE11 settings -> security -> and set (or remove) the "protected mode" flag for each zone (The value can be on or off, as long as it is the same for every zone)
3) use this modified script for the quick test

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

Local Enum $eFireFox = 0, _
        $eChrome, _
        $eIE

Local $aTestSuite[][2] = [["TestTimeouts", False],["TestNavigation", False],["TestElements", False],["TestScript", False],["TestCookies", False],["TestAlerts", True]]

Local Const $_TestType = $eIE ; $eFireFox
Local $sDesiredCapabilities
Local $iIndex
Local $sSession

$_WD_DEBUG = True

Switch $_TestType
    Case $eFireFox
        SetupGecko()

    Case $eChrome
        SetupChrome()

    Case $eIE
        SetupIE()

EndSwitch

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)

For $iIndex = 0 To UBound($aTestSuite, $UBOUND_ROWS) - 1
    If $aTestSuite[$iIndex][1] Then
        ConsoleWrite("Running: " & $aTestSuite[$iIndex][0] & @CRLF)
        Call($aTestSuite[$iIndex][0])
    Else
        ConsoleWrite("Bypass: " & $aTestSuite[$iIndex][0] & @CRLF)
    EndIf
Next

_WD_DeleteSession($sSession)
_WD_Shutdown()


Func TestTimeouts()
    _WD_Timeouts($sSession)
    _WD_Timeouts($sSession, '{"pageLoad":2000}')
    _WD_Timeouts($sSession)
EndFunc   ;==>TestTimeouts

Func TestNavigation()
    _WD_Navigate($sSession, "http://google.com")
    ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
    _WD_Action($sSession, "back")
    ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
    _WD_Action($sSession, "forward")
    ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
    ConsoleWrite("Title=" & _WD_Action($sSession, 'title') & @CRLF)
EndFunc   ;==>TestNavigation

;_WDWindow($sSession, 'frame', '{"id":nullelse
Func TestElements()
    Local $sElement, $aElements, $sValue

    _WD_Navigate($sSession, "http://google.com")
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='lst-ib1']")

    If @error = $_WD_ERROR_NoMatch Then
        $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='lst-ib']")
    EndIf

    $aElements = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div/input", '', True)

    _ArrayDisplay($aElements)

    _WD_ElementAction($sSession, $sElement, 'value', "testing 123")
    Sleep(500)

    _WD_ElementAction($sSession, $sElement, 'text')
    _WD_ElementAction($sSession, $sElement, 'clear')
    Sleep(500)
    _WD_ElementAction($sSession, $sElement, 'value', "abc xyz")
    Sleep(500)
    _WD_ElementAction($sSession, $sElement, 'text')
    _WD_ElementAction($sSession, $sElement, 'clear')
    Sleep(500)
    _WD_ElementAction($sSession, $sElement, 'value', "fujimo")
    Sleep(500)
    _WD_ElementAction($sSession, $sElement, 'text')
    _WD_ElementAction($sSession, $sElement, 'click')

    _WD_ElementAction($sSession, $sElement, 'Attribute', 'text')

    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='lst-ib']")
    $sValue = _WD_ElementAction($sSession, $sElement, 'property', 'value')

    ConsoleWrite('value = ' & $sValue & @CRLF)

EndFunc   ;==>TestElements

Func TestScript()
    _WD_ExecuteScript($sSession, "return arguments[0].second;", '{"first": "1st", "second": "2nd", "third": "3rd"}')
    _WD_Alert($sSession, 'Dismiss')
EndFunc   ;==>TestScript

Func TestCookies()
    _WD_Navigate($sSession, "http://google.com")
    _WD_Cookies($sSession, 'Get', 'NID')
EndFunc   ;==>TestCookies

Func TestAlerts()
    ConsoleWrite('Alert Detected => ' & _WD_Alert($sSession, 'status') & @CRLF)
    _WD_ExecuteScript($sSession, "alert('testing 123')")
    ConsoleWrite('Alert Detected => ' & _WD_Alert($sSession, 'status') & @CRLF)
    ConsoleWrite('Text Detected => ' & _WD_Alert($sSession, 'gettext') & @CRLF)
    _WD_Alert($sSession, 'sendtext', 'new text')
    ConsoleWrite('Text Detected => ' & _WD_Alert($sSession, 'gettext') & @CRLF)
    Sleep(5000)
    _WD_Alert($sSession, 'Dismiss')

EndFunc   ;==>TestAlerts


Func SetupGecko()
    _WD_Option('Driver', 'geckodriver.exe')
    _WD_Option('DriverParams', '--log trace')
    _WD_Option('Port', 4444)

    $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'
EndFunc   ;==>SetupGecko

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

    $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true }}}}'
EndFunc   ;==>SetupChrome

Func SetupIE()
    _WD_Option('Driver', 'IEDriverServer.exe')
    _WD_Option('Port', 5555)
    _WD_Option('DriverParams', '--log-file=' & @ScriptDir & '\IE.log')

    $sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true}}'
EndFunc   ;==>SetupIE

 

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Share this post


Link to post
Share on other sites

I've been looking through the samples but couldn't find what I was looking for. How do we connect to an existing session? 

Share this post


Link to post
Share on other sites
2 hours ago, ban64 said:

I've been looking through the samples but couldn't find what I was looking for. How do we connect to an existing session? 

This is controlled by the parameters passed to the specific driver when launched. If you look here, you will see that the Mozilla Geckodriver supports the option "--connect-existing". You would use _WD_Option to set the DriverParams option before calling _WD_Startup.

Share this post


Link to post
Share on other sites

Hello,

first of all thx @Danp2 for this great WD UDF. ^_^ It helps a lot for repeating work and speed in browsing. :-)

One question: i start a new firefox session and i´m missing my already included add-ons, which i like to refer during execution of some scripts.

Is there a way to start a new session wit FF Browser including Add-ons?

many thx,

horphi

 

Share this post


Link to post
Share on other sites
On 2/4/2018 at 2:19 AM, Danp2 said:

@NguyenLe Just check @error after the function call, like this --

SetupGecko()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, 'http://google.com')
$sElement = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//a[@class='gsfi']")

If @error = $_WD_ERROR_Success Then
    _WD_ElementAction($sSession, $sElement, 'value','Hello')
EndIf

 

What i do, if i cannot really identify an unique object, i switch to wd_script for instance...

 

Func _attach() ;--> open attachment dialog
    $sinputATT = "document.getElementsByName('attachment')[0].click();" 
    _WD_ExecuteScript($sSession, $sinputATT)

EndFunc   ;==>_attach

BR

Share this post


Link to post
Share on other sites
53 minutes ago, horphi said:

Is there a way to start a new session wit FF Browser including Add-ons?

This would be controlled using the DesiredCapabilities parameter that gets passed to _WD_CreateSession. 

Each driver has it's own implementation method. You can gather more details at these links --

https://github.com/mozilla/geckodriver

https://sites.google.com/a/chromium.org/chromedriver/capabilities

Share this post


Link to post
Share on other sites

Hi,

When I want to invoke a search box in the web driver session, sending "^F" or "!F" is not working. It works outside of the script, but it doesn't inside the script.

I'm going around by clicking the setting button and sending "F".

Am I doing anything wrong?

$_WD_DEBUG = False
SetupChrome()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://www.88countryclub.co.kr/")
$hwnd = WinWaitActive("88")
WinSetState($hwnd, "", @SW_MAXIMIZE)
Sleep(1000)
Send("^F")

 

Share this post


Link to post
Share on other sites
4 minutes ago, CYCho said:

ControlSend($hwnd, "", "", "^f") does not work either. I can't find a suitable webdriver command in your UDFs.

It did in my testing. Here's the complete code --

#include "wd_core.au3"

Local $sDesiredCapabilities

$_WD_DEBUG = False

SetupChrome()
_WD_Startup()
$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://www.88countryclub.co.kr/")
$hwnd = WinWaitActive("88")
WinSetState($hwnd, "", @SW_MAXIMIZE)

Sleep(1000)
ControlSend($hwnd, "", "", "^f")

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

$sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"chromeOptions": {"w3c": true }}}}'
EndFunc

 

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Jgladden
      Dan - thanks for all that you do - this stuff is great. 
      Hoping you can assist with an issue we are having now that we have moved to Windows 10/Server 2016. The Chrome interactions were working flawlessly until moving over. Now my code fails when attempting to create the session. As you can see, our Chrome install is not in a standard location but I have validated the path to the binary. I have attached some detail below including system info, console output and the chrome log detail. I have tried several recommendations that have seen in various forums but none have made a difference
      Any assistance you can give would be greatly appreciated. 
      Thanks in advance, 
      chrome_Details.txt
    • By Langmeister
      I am once again asking for your experienced assistance. If I open a website that uses notifications I am asked to allow or block them for that website after a few seconds. This notification pops up every time the page gets navigated to, even tho you have clicked on allow for several times. I am explicitly not searching for smth to get rid of "Chrome is being controlled by automated test sw". Instead I am searching for a line of script to disable all notifications by default: like here chrome://settings/content/notifications. 
      This is code should give you an example of what notifications I am talking about:
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://webradio.planetradio.de/") _WD_LoadWait($sSession)  
    • By Langmeister
      Hi, I'm sure that this is a simple question regarding webdriver udf but my search on the forum did not result in the exact same scenario that I need. I will adapt it to my corporate needs but at first I want it to work with an example everybody can reproduce if needed.
      I navigate to https://www.daysoftheyear.com/ and want to find out what special day today is. Using the following Code returns the wanted text that today is 'shark awareness day' in the console but it is not pasted in notepad as it is not copied as it probably should be.
      #include "wd_core.au3" #include "wd_helper.au3" Local $sDesiredCapabilities, $sSession, $sID _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") _WD_Option('Port', 9515) _WD_Option('DriverParams', '--log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}' _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://www.daysoftheyear.com/?timezone_offset=nan") _WD_LoadWait($sSession) Sleep(3000) Local $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[2]/header/div/div[1]/div/div[2]/h3/a") _WD_ElementAction($sSession, $sElement, 'text') ClipGet() Run("notepad.exe") Sleep(500) Send("^v") Scite returns this, therefore the text has been found but the last mile to paste it to notepad or excel does not work for me.
      __WD_Get: URL=HTTP://127.0.0.1:9515/session/b72166b774d7fefb258b3721fc1d4306/element/657e6b5d-31a9-46a8-85c4-acb7f72bf659/text __WD_Get: StatusCode=200; $iResult = 0; $sResponseText={"value":"Shark Awareness Day"}... _WD_ElementAction: {"value":"Shark Awareness Day"}... Thanks in advance! 
       
    • By Langmeister
      Hi, I need help performing actions in Salesforce using IE. I used to complete tasks via MouseMove/MouseClick etc. on the Chrome application of SF, but unfortunately this only works for me and not my colleagues due to different positions of things etc. Being unable to get Webdriver UDF or Chromedriver running to interact with the code directly, I chose to look into the IE UDF. ATM I'm trying to tick a specific checkbox in SF which simply allows me to "select all checkboxes" at the same time. Applying the following code on a random website with checkboxes works just fine for me: (in this case selecting cheese checkbox)
      #include <IE.au3> Local $oIE = _IECreate("http://www.echoecho.com/htmlforms09.htm") Local $oSubmit = _IEGetObjByName($oIE, "option3") _IEAction($oSubmit, "click") _IELoadWait($oIE) But applying it to the Salesforce website it does exactly nothing and responds with these warnings/errors:
      The script is exactly the same, except for website and the input name tag of the desired checkbox being different.
      #include <IE.au3> Local $oIE = _IECreate("Corporate Salesforce URL") Local $oSubmit = _IEGetObjByName($oIE, "myPage:myForm:oliListBlock:oliListTable:j_id36") _IEAction($oSubmit, "click") _IELoadWait($oIE) As its working with random websites my guess is that there has to be something done to get it work with SF.
      Hope the more experienced SF+AutoIt pros can help me out here. Thanks in advance!
    • By JohnWIlling
      We are running on a VIrtual Machine via Remote Desktop.  We are having a situation where the loading of the chromedriver.exe is taking longer on the VM than on a physical machine.  It is causing the first call to  WD_Post in _WD_CreateSession to fail.
      To workaround the Issue, I used a simplified version of (_WinAPI_GetTcpTable) UDF to Loop waiting for the driver port to be in the listening state.  At that point, I know that the Post will work:
      Func _WaitForPort($ListenPort) Do Local $tMIB_TCPTABLE = DllStructCreate("dword[6]") Local $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", 0, "BOOL", True) Local $dwSize = $aRet[2] $tMIB_TCPTABLE = DllStructCreate("DWORD[" & $dwSize / 4 & "]") $aRet = DllCall("Iphlpapi.dll", "DWORD", "GetTcpTable", "struct*", $tMIB_TCPTABLE, "DWORD*", $dwSize, "BOOL", True) If $aRet[0] <> 0 Then Return SetError(1) Local $iNumEntries = DllStructGetData($tMIB_TCPTABLE, 1, 1) Local $aRes[$iNumEntries][6] For $i = 0 To $iNumEntries - 1 Local $Type = DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 0) $aRet = DllCall("ws2_32.dll", "ushort", "ntohs", "uint", DllStructGetData($tMIB_TCPTABLE, 1, 2 + $i * 5 + 2)) ; local port Local $Port = $aRet[0] ConsoleWrite("Checking Row:" & $i & " State:<" & $Type & "> Port:<" & $Port & ">" & @CRLF) ; Type 2 is LISTENING If $Type = 2 And $Port = $ListenPort Then Return 1; EndIF Next Sleep(500); Until 0; Return 0; EndFunc ;==>_WaitForPort  
×
×
  • Create New...