Jump to content

WebDriver UDF - Help & Support


Recommended Posts

  • Replies 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

This is the "General Help and Support" thread for the WebDriver UDF. The UDF itself can be downloaded here. So if you have any questions, suggestions or errors please post here.

use the _WD_ElementAction function like this: $sValue = _WD_ElementAction($sSession, $sElement, 'attribute', 'src') p.s. ... and remove @src from the xPath: "//img[@alt='NiceGirl']"

Time ago I wrote a function to extract data from  the source HTML code of tables. https://www.autoitscript.com/forum/topic/167679-read-data-from-html-tables-from-raw-html-source/ Seems that that fun

Posted Images

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
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.

 

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"}}

 

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

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.

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
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?

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
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.

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
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 TTE26
      For the past two days I've been reading all Wiki pages, installed all the demos etc. but I am still unable to do this simple workflow
      1. I want to use WebDriver UDF to open Chrome (Set chrome option arguments - Window Size, Pixel ratio, device type and platform name, user-agent.)
      2. On new Tab I want to read the tab Title and save it into a TXT file.
      3. I need to save the Session ID with my previosly set Capabilities into a file.
      4. I want to close the chrome window.
      Then
      5. I want to open Chrome again, but with my previosly saved Session ID and Capabilities list from the file.
      6. And minimaze the window state.
      7. After 30 seconds, close the chrome.
      I would really appreciate for the WebDriver UDF Helper file, to have also basic code examples, for non coders. For example how to open a windwow etc., save sessions, etc.
      Anyway, if someone could help me get started and help me with this workflow, that would be much appreaciated. 😔
    • By lapoelkan12
      hi i try to use webdriver  i download it and  download json and  winhttp i try to run it  but  return error
       error: __WinHttpVer(): undefined function.
              Local $sWinHttpVer = __WinHttpVer()
              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
       
       

    • By levila
      Hi Guys, i just do some codding to automate login to some of the web.
      I manage to do the script but somehow after script done, some weird box popup. and keep looping until i close the main chrome.exe

      here is my code. kinldy pls assist, im very new to webdriver udf.
      #NoTrayIcon #include "wd_core.au3" #include "wd_helper.au3" $_WD_DEBUG = $_WD_DEBUG_None ; You could also use $_WD_DEBUG_Error Local $sDesiredCapabilities, $sSession SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) _WD_Navigate($sSession, "https://someoftheweb.com") _ChromeSetInputValueByName($sSession, "inputName", "Username") _ChromeSetInputValueById($sSession, "inputPassword", "Password") _ChromeSetMouseClick($sSession, "submit", "click") _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, "args":["--no-sandbox"]}}}}' EndFunc Func _ChromeSetInputValueByName($sSession,$name,$Value) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$name&"']") _WD_ElementAction($sSession,$sButton,'value', $Value) EndFunc Func _ChromeSetInputValueById($sSession,$Id,$Value) $sButton = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='"&$Id&"']") _WD_ElementAction($sSession,$sButton,'value', $Value) EndFunc Func _ChromeSetMouseClick($sSession,$Id,$Value) $sButton = _WD_FindElement($sSession,$_WD_LOCATOR_ByXPath,"//button[@type='"&$Id&"']") _WD_ElementAction($sSession, $sButton, 'click', $Value) EndFunc  
    • By RohanM
      Hi Team,
      is there is a way to embed the webpage in auto it GUI using webdriver? what I want to do is that, I want to open edge browser inside the AutoIT GUI, in IE we have _IECreateEmbedded function but for the webdriver I am not able to find a function, please help  
      Rohan M
    • By goku200
      I am trying to change the settings of the print option to Save as PDF and its not changing the settings and clicking on the Save button at the bottom. Here is my script that I have written and the format is correct below. Chrome browser I'm using is 97.0 My script was working fine using Chrome 95.0\ Not sure why its not working now
      It finds the print-preview-app element but not the others.
       
×
×
  • Create New...