Jump to content

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
Link to comment
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 comment
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")

Link to comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...