Jump to content
Danp2

WebDriver UDF - Help & Support

Recommended Posts

that is what is im saying why is a "space" breaking my code? I'm going to try and remove the last char from the string and see if it works.  

it worked. :( i have no idea what is causing this to break other then some invisible char 

Edited by nooneclose

Share this post


Link to post
Share on other sites

@Danp2 It was a @CRLF that was causing the string to "break". Somehow between reading the email and sending the variable a @CRLF got placed at the end. I did a 

StringReplace($eComments, @CRLF, "")

 and it works now every time.

I need a nap after that rabit trail which turned into a chaos tornado. 🤣

Share this post


Link to post
Share on other sites
Func _WD_ElementAction($sSession, $sElement, $sCommand, $sOption = '')
    Local Const $sFuncName = "_WD_ElementAction"
    Local $sResponse, $sResult = '', $iErr, $oJson, $sErr

    $sCommand = StringLower($sCommand)

    Switch $sCommand
        Case 'attribute', 'property', 'css'
            $sResponse = __WD_Get($_Glo_BASE_URL & ":" & $_Glo_PORT & "/session/" & $sSession & "/element/" & $sElement & "/" & $sCommand & "/" & $sOption)
            $iErr = @error

As described in the above function,

it seems that it can only be applied to a known "$sOption" of an element.

How can I enumerate all the properties of this element?

lcoal $a=_WD_ElementAction($sSession, $sElement,'attribute', '')
or
lcoal $a=_WD_ElementAction($sSession, $sElement,'attributes', '')


lcoal $a=_WD_ElementAction($sSession, $sElement,'property', '')
or
lcoal $a=_WD_ElementAction($sSession, $sElement,'properties', '')

Can't get a valid return value.

 

Share this post


Link to post
Share on other sites

@Letraindusoir I think you may find your answer in the wd_core.au3 under the "_WD_ElementAction" section.

if you are wanting a list of its capabilities.  

Edited by nooneclose

Share this post


Link to post
Share on other sites

How to set referer? I tried this :Global $hRequest = _WinHttpSimpleSendRequest($hConnect, Default, "test.php",default,default,'referer:www.google.com') .It works. But I don't know how to  set referer with this: _WD_Navigate($sSession, "http://google.com")

Share this post


Link to post
Share on other sites

I tried to use the demo file to modify the automated Bing search operation, but it didn't seem to work properly.

Autoit3 Code:

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

Local $sDesiredCapabilities
Local $iIndex
Local $sSession

SetupChrome()

_WD_Startup()

$sSession = _WD_CreateSession($sDesiredCapabilities)
_WD_Navigate($sSession, "https://www.bing.com")
$qinput=_WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='sb_form_q']")
ConsoleWrite('inputid : '&$qinput&@CR)
_WD_ElementAction($sSession, $qinput, 'value', "testing 123")
;~ _WD_DeleteSession($sSession)
;~ _WD_Shutdown()

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 }}}}'
EndFunc

Console Output:

_WDStartup: OS: WIN_7 WIN32_NT 7601 Service Pack 1
_WDStartup: AutoIt: 3.3.14.5
_WDStartup: WD.au3: 0.1.0.21
_WDStartup: Driver: chromedriver.exe
_WDStartup: Params: --log-path="C:\Users\Administrator\Desktop\webdrv\WebDriver-0.1.0.21\chrome.log"
_WDStartup: Port:   9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true }}}}
__WD_Post: StatusCode=0; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"77.0.3865.90","chrome":{"chromedriverVersion":"77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865@{#442})","userDataDir":"C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\scoped_dir3880_1172536147"},"goog:chromeOptions":{"debuggerAddress":"localhost:49946"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows nt","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"},"sessionId":"b66971f3059784520188f6236c20feda"}}
_WD_CreateSession: {"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"77.0.3865.90","chrome":{"chromedriverVersion":"77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865@{#442})","userDataDir":"C:\\Users\\ADMINI~1\\AppData\\Local\\Temp\\scoped_dir3880_1172536147"},"goog:chromeOptions":{"debuggerAddress":"localhost:49946"},"networkConnectionEnabled":false,"pageLoadStrategy":"normal","platformName":"windows nt","proxy":{},"setWindowRect":true,"strictFileInteractability":false,"timeouts":{"implicit":0,"pageLoad":300000,"script":30000},"unhandledPromptBehavior":"dismiss and notify"},"sessionId":"b66971f3059784520188f6236c20feda"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/b66971f3059784520188f6236c20feda/url; $sData={"url":"https://www.bing.com"}
__WD_Post: StatusCode=0; ResponseText={"value":null}
_WD_Navigate: {"value":null}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/b66971f3059784520188f6236c20feda/element; $sData={"using":"xpath","value":"//input[@id='sb_form_q']"}
__WD_Post: StatusCode=0; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"7cd8d609-ef1f-44f5-a803-3eb3f044163f"}}
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"7cd8d609-ef1f-44f5-a803-3eb3f044163f"}}
_WD_FindElement ==> Webdriver Exception: HTTP status = 0
inputid : 
__WD_Post: URL=HTTP://127.0.0.1:9515/session/b66971f3059784520188f6236c20feda/element//value; $sData={"id":"", "text":"testing 123"}
__WD_Post: StatusCode=0; ResponseText={"value":{"error":"no such element","message":"no such element: Element_id length is invalid\n  (Session info: chrome=77.0.3865.90)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0119EB13+1501971]\n\tOrdinal0 [0x0111F6D1+980689]\n\tOrdinal0 [0x010A765F+489055]\n\tOrdinal0 [0x01046A89+92809]\n\tOrdinal0 [0x01043720+79648]\n\tOrdinal0 [0x01057A4D+162381]\n\tOrdinal0 [0x01042656+75350]\n\tOrdinal0 [0x01057C61+162913]\n\tOrdinal0 [0x0105F93E+194878]\n\tOrdinal0 [0x010578EB+162027]\n\tOrdinal0 [0x01040AC7+68295]\n\tOrdinal0 [0x01041B40+72512]\n\tOrdinal0 [0x01041AD9+72409]\n\tOrdinal0 [0x01138F37+1085239]\n\tGetHandleVerifier [0x0123D7ED+503293]\n\tGetHandleVerifier [0x0123D580+502672]\n\tGetHandleVerifier [0x012446AC+531644]\n\tGetHandleVerifier [0x0123DFFA+505354]\n\tOrdinal0 [0x01130606+1050118]\n\tOrdinal0 [0x0113047F+1049727]\n\tOrdinal0 [0x0113AF9B+1093531]\n\tOrdinal0 [0x0113B103+1093891]\n\tOrdinal0 [0x0113A095+1089685]\n\tBaseThreadInitThunk [0x7693343D+18]\n\tRtlInitializeExceptionChain [0x77039802+99]\n\tRtlInitializeExceptionChain [0x770397D5+54]\n"}}
_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=77.0.3865.90)","stacktrace":"Backtrace:\n\tOrdinal0 [0x0119EB13+1501971]\n\tOrdinal0 [0x0111F6D1+980689]\n\tOrdinal0 [0x010A765F+489055]\n\tOrdinal0 [0x01046A89+92809]\n\tOrdinal0 [0x01043720+79648]\n\tOrdinal0 [0x01057A4D+162381]\n\tOrdinal0 [0x01042656+75350]\n\tOrdinal0 [0x01057C61+162913]\n\tOrdinal0 [0x0105F93E+194878]\n\tOrdinal0 [0x010578EB+162027]\n\tOrdinal0 [0x01040AC7+68295]\n\tOrdinal0 [0x01041B40+72512]\n\tOrdinal0 [0x01041AD9+72409]\n\tOrdinal0 [0x01138F37+1085239]\n\tGetHandleVerifier [0x0123D7ED+503293]\n\tGetHandleVerifier [0x0123D580+502672]\n\tGetHandleVerifier [0x012446AC+531644]\n\tGetHandleVerifier [0x0123DFFA+505354]\n\tOrdinal0 [0x01130606+1050118]\n\tOrdinal0 [0x0113047F+1049727]\n\tOrdinal0 [0x0113AF9B+1093531]\n\tOrdinal0 [0x0113B103+1093891]\n\tOrdinal0 [0x0113A095+1089685]\n\tBaseThreadInitThunk [0x7693343D+18]\n\tRtlInitializeExceptionChain [0x77039802+99]\n\tRtlInitializeExceptionChain [0x770397D5+54]\n"}}

 

Share this post


Link to post
Share on other sites

@Danp2  When I run the program ,it will open a new firefox without any extension. I want to get the existed extensions I‘ve installed before in firefox.What should I do? I tried this code:$sDesiredCapabilities = '{"desiredCapabilities":{"javascriptEnabled":true,"nativeEvents":true,"acceptInsecureCerts":true,"args": ["-profile", "C:\\Users\\gens\\AppData\\Local\\Mozilla\\Firefox\\Profiles\\g2h1nwi0.default-release"]}}', but it did't work.   Or how to install brower  extensions automatically? Thanks

Share this post


Link to post
Share on other sites
7 hours ago, tigerwang said:

How to set referer? I tried this :Global $hRequest = _WinHttpSimpleSendRequest($hConnect, Default, "test.php",default,default,'referer:www.google.com') .It works. But I don't know how to  set referer with this: _WD_Navigate($sSession, "http://google.com") 

Not something I've needed to do, and some quick research seems to indicate that you need to use a proxy to accomplish this.

Share this post


Link to post
Share on other sites
5 hours ago, TOMLE said:

_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"7cd8d609-ef1f-44f5-a803-3eb3f044163f"}}
_
WD_FindElement ==> Webdriver Exception: HTTP status = 0
inputid :

Not sure why this would be occurring. When I ran your code, it executed fine for me. It appears that we are using the same version of all components. <shrug>

I seem to recall an earlier bug where the function improperly returned the Webdriver Exception error, but I thought this had been addressed already. I'll take another peek at the code to see if I can see why this might occur.

Edit:

Quote
__WD_Post: StatusCode=0; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"7cd8d609-ef1f-44f5-a803-3eb3f044163f"}}

This is the issue. StatusCode here should be 200, not 0.

Edit #2:

Now I remember the cause. You need to update to the latest version of the WinHTTP UDF to resolve this issue.

Edited by Danp2

Share this post


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

Not something I've needed to do, and some quick research seems to indicate that you need to use a proxy to accomplish this.

Maybe my idea is not clear.We can load page by _WD_Navigate($sSession,$url)  so  far.I want to get referer in the page of $url. Like this:_WD_Navigate($sSession,$url,$referer).

I  can get the $referer in the $url page. It means that someone comes to the $url page from the $referer page.  I could't  set  it like that. Could you give me some advice?

Share this post


Link to post
Share on other sites
$sElement1 = _WD_FindElement($sSession,"xpath",'//*[@id="' & $sEleID & '"]')


$sResp = _WD_ExecuteScript($sSession, 'var e = document.getElementById("' & $sEleID & '");return e;', '')
$oJSon = Json_Decode($sResp)
$sElement2 = Json_Get($oJSon, '[value]["element-6066-11e4-a52e-4f735466cecf"]')


$sS = ""
    $sS &= 'var xresult = document.evaluate("//*[@id=' & "'" & $sEleID & "'" & ']", document, null, XPathResult.ANY_TYPE, null);'
    $sS &= 'var xnodes = [];'
    $sS &= 'var xres;'
    $sS &= 'while (xres = xresult.iterateNext()) {'
    $sS &= '    xnodes.push(xres);'
    $sS &= '    };'
    $sS &= 'return xnodes;'
    $sResp = _WD_ExecuteScript($sSession, $sS, '')
    $oJSon = Json_Decode($sResp)
$sElement3 = Json_Get($oJSon, '[value][0]["element-6066-11e4-a52e-4f735466cecf"]')

After running the above script,

By comparison ,shows that $sElement1=$sElement2=$sElement3.

It feels like there's an inner relationship between them.

Is there any way to convert or map "$sElement1"  to a DOM or Javascript object so that we can manipulate the web page directly by calling the object's methods or properties?

Edited by Letraindusoir

Share this post


Link to post
Share on other sites
22 minutes ago, Letraindusoir said:

By comparison ,shows that $sElement1=$sElement2=$sElement3.

Why would you expect these to be different when you're using the same criteria to select them?

Also, why not post an example we can actually run rather than just this snippet of code? :rolleyes:

23 minutes ago, Letraindusoir said:

Is there any way to convert or map "$sElement1"  to a DOM or Javascript object so that we can manipulate the web page directly by calling the object's methods or properties?

Yes... you pass $sElement1 as a parameter to _WD_ExecuteScript and then access that parameter within the executed javascript. I believe there are already examples of this on the forum.

Share this post


Link to post
Share on other sites

Hello everyone! I have a quick questions on how to use jQuery in this code to select the text.

<div class="cx-item-contents">4:00 am</div><div class="cx-item-contents">8:00 am</div>
<div class="cx-item-contents">10:00 am</div><div class="cx-item-contents">8:00 am</div>
$sButton = _WD_ExecuteScript($sSession, "jQuery('.cx-item-contents').click()")

When I run the above script it select all of the checkbox with the class=cx-item-contents. How do I make it select the box by the text only. Example! check both 8:00 am boxes or check 4:00 am plus 10:00 am box only.

Thanks in advanced!!!

Edited by OneSolution

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Danp2
      Introduction
      This UDF will allow you to interact with any browser that supports the W3C WebDriver specifications. Supporting multiple browsers via the same code base is now possible with just a few configuration settings.
      Requirements
      JSON UDF https://www.autoitscript.com/forum/topic/148114-a-non-strict-json-udf-jsmn
      WinHTTP UDF https://www.autoitscript.com/forum/topic/84133-winhttp-functions/
      HtmlTable2Array UDF (optional) https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/
      WebDriver for desired browser
      Chrome WebDriver https://sites.google.com/a/chromium.org/chromedriver/downloads FireFox WebDriver https://github.com/mozilla/geckodriver/releases Edge WebDriver https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/ Source Code
      You will always be able to find the latest version in the GitHub Repo 
      Help / Support
      See the wiki for details on the UDF --
      https://www.autoitscript.com/wiki/WebDriver
      Please post any questions, suggestions or errors in the GH&S thread.
      https://www.autoitscript.com/forum/topic/201106-webdriver-udf-help-support-ii/
    • 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!
×
×
  • Create New...