Jump to content

WebDriver UDF - Help & Support


Recommended Posts

Yes, you were right. I found this code (click 2) attached to the link element. If I click on "trigger event" it opens the upload tab as it should. (but not with Autoit) Do you see a problem with this code? Click 1 code is visible on the screenshot.

function (event) {
    var $this = $(this),
        method = $this.data('method'),
        message = $this.data('confirm'),
        form = $this.data('form');
 
    if (method === undefined && message === undefined && form === undefined) {
        return true;
    }
 
    if (message !== undefined) {
        $.proxy(pub.confirm, this)(message, function () {
            pub.handleAction($this, event);
        });
    } else {
        pub.handleAction($this, event);
    }
    event.stopImmediatePropagation();
    return false;
}

Screenshot (4).png

Link to comment
Share on other sites

@_leo_ You have two different click events attached to the link. When you clicked "trigger event", I believe you were triggering the first click event, which is different code than what you posted above. This is the actual code attached to that event --

function(e) {
  !0 === e ? (ga("send", {
    hitType: "event",
    eventCategory: "FileLibrary",
    eventAction: "Default file upload"
  }), $(this.nodeFilter).find("input[type=file]").click()) : PF.FileLibrary.CopyrightWarning.showPopup($.proxy(this.onDefaultUploadClick, this, !0, !1))
}

 

Link to comment
Share on other sites

FYI, I just ran the following in Chrome and it triggered the file upload dialog for me --

_WD_Navigate($sSession, "https://www.printful.com/dashboard/library")
$Upload = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//a[@class='btn btn-danger btn-block' and contains(text(),'Upload')]")
_WD_ElementAction($sSession, $Upload, 'click')

 

Link to comment
Share on other sites

Thank you very much @Danp2, that sounds very promising! 

When I clicked "trigger event" it triggered the file upload dialog on both click events attached to the element. I do not understand where you got this different Javascript code from. As you can see on the screenshot, the code attached to the Upload button seems to be another one than yours.

If I try to trigger the event with the same code, I still don't get a reaction. Could it be that the problem is not caused by a javascript error? This would explain why it works for you.

I am very thankful that you created an account just to help - that is so kind.

412688758_Screenshot(6).thumb.png.ac6c2046110c59a411f87f62465dfb12.png

Edited by _leo_
Link to comment
Share on other sites

I downloaded the newest release of the UDF, tried to use the 78 chromedriver (that does not work at all) and checked if Javascript was still enabled in the chrome settings. None of the actions solved the problem. Maybe I should try it on my other laptop...

Quote

_WDStartup: OS:    WIN_10 WIN32_NT 17763 
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.1.0.21
_WDStartup: Driver:    chromedriver.exe
_WDStartup: Params:    --log-path="C:\Users\leona\Desktop\chrome.log"
_WDStartup: Port:    9515
__WD_Post: URL=HTTP://127.0.0.1:9515/session; $sData={"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["start-maximized", "disable-infobars", "user-data-dir=userdata"] }}}}
__WD_Post: StatusCode=200; ResponseText={"value":{"capabilities":{"acceptInsecureCerts":false,"browserName":"chrome","browserVersion":"77.0.3865.90","chrome":{"chromedriverVersion":"77.0.3865.40

Link to comment
Share on other sites

There are some things that  I don't quite understand about _ WD_ExecuteScript.

_WD_ExecuteScript($sSession, $sScript, $sArguments = "[]", $lAsync = False)

$sData = '{"script":"' & $sScript & '", "args":[' & $sArguments & ']}'

If there are three parameters

Arguments[0]=100

Arguments[1]="Status"

Arguments[2]=@CRLF

_WD_ExecuteScript($Session, $sScript, $sArguments)

how do I write '$sArguments' ?

_WD_ExecuteScript($Session, $sScript,'100,"Status",@CRLF')

or 

_WD_ExecuteScript($Session, $sScript,'[100,"Status",@CRLF]')

Is that so?

Link to comment
Share on other sites

@Letraindusoir The brackets are added by _WD_ExecuteScript automatically, so I would say that the first one is the better of the two attempts.

Both _WD_NewTab and _WD_GetElementFromPoint pass multiple parameters to _WD_ExecuteScript, so you may want to review those functions for other working examples.

Link to comment
Share on other sites

Good morning, Danp2. Quick question. I am having issues sending data to a field.

I am wanting to send data to a Long Description Box that pops up when its clicked. 

Here is a picture of what I am talking about: (Trying to send data to the green highlighted box, the red box is the details about that element)

315537226_Screenshot(35).thumb.png.8ce61fc6cbd8fc751c66185080b9cbb6.png

The box is a div with an id of "dijitEditorBody".

Here is the code I have so far. (edited: I doubt you want all 230 lines)

;===============================================================================
    ; Send Data to the Long Description
    ; Clicks the Long Description Button
    Local $wLongok   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//img[@id='mad3161b5-img2']")
    _WD_ElementAction($sSession, $wLongok, 'click')
    Sleep(5000)
    
    ; Sends the Long Description to the LongD TextBox
    Local $eDescription   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='dijitEditorBody']")
    _WD_ElementAction($sSession, $eDescription, 'value', "Can I add a Long Description or are you just joshing me?")
    _WD_ElementAction($sSession, $eDescription, 'text')
    Sleep(500)
    
    ; Clicks OK to close TextBox
    Local $wLongok   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='m74031266-pb']")
    _WD_ElementAction($sSession, $wLongok, 'click')
    Sleep(500)

everything else works except for the long description. I do not know if its because a new window appears or if its because it is a "div".

As always any help would be greatly appreciated. 

Link to comment
Share on other sites

@Danp2 Thank you for getting back with me. I did find out about the iframe but I don't really know how to handle it.

The best I could come up with was: (this didn't work, I do not know how to properly handle iframes.)

Local $eDescription   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='ma6499a9c-rte_iframe']")
    _WD_ElementAction($sSession, $eDescription, 'value', "Can I add a Long Description or are you just joshing me?")
    _WD_ElementAction($sSession, $eDescription, 'text')
    Sleep(500)

 

Link to comment
Share on other sites

I'm sorry im still not understanding what to do with iframes. I ran the demo multiple times and I ran that demo code in my script and I still do not understand what I am supposed to do with them. 

These are the results I get in my script: (from the code below)

Frames=3
TopWindow=True
TopWindow=False
TopWindow=True

here is the code I used:

ConsoleWrite(@CRLF & @CRLF & @CRLF & @CRLF & "Frames=" & _WD_GetFrameCount($sSession) & @CRLF)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='ma6499a9c-rte_iframe']")
    _WD_FrameEnter($sSession, $sElement)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)
    _WD_FrameLeave($sSession)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)

Am I supposed to perform an action? after I enter the frame? 

Edited by nooneclose
Link to comment
Share on other sites

@Danp2 Hello, I have a confusing question. Remember yesterday how I got my code to work on my test site. Welp, I can not get it to run on the live site. :( 

There is almost no difference between the test and the live site. (the only difference I have found is that sometimes the id's are different)

Here is the code I have to send data to the "div" inside of the "iframe":

; Click the Long Description button
        Local $wLongDB = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//img[@id='m65d795a4-img']")
        _WD_ElementAction($sSession, $wLongDB, 'click')
        Sleep(5000)

        ConsoleWrite(@CRLF & @CRLF & @CRLF & @CRLF & "Frames=" & _WD_GetFrameCount($sSession) & @CRLF)
        ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)


        $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='ma6499a9c-rte_iframe']")
        _WD_FrameEnter($sSession, $sElement)
        ConsoleWrite(@CRLF & @CRLF & @CRLF & @CRLF & "Frames=" & _WD_GetFrameCount($sSession) & @CRLF)
        ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)
        Local $wLongTxtBox   = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//div[@id='dijitEditorBody']")
        _WD_ElementAction($sSession, $wLongTxtBox, 'value', $eComments)
        _WD_ElementAction($sSession, $wLongTxtBox, 'text')
        _WD_FrameLeave($sSession)


        ConsoleWrite(@CRLF & @CRLF & @CRLF & @CRLF & "Frames=" & _WD_GetFrameCount($sSession) & @CRLF)
        ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)
        Sleep(3500)


        ; Click the ok button
        Sleep(2000)
        Local $wLongOk = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//button[@id='m74031266-pb']")
        _WD_ElementAction($sSession, $wLongOk, 'click')
        Sleep(2500)

Here are the iframe results:

Frames=2
TopWindow=True

Frames=0
TopWindow=False

Frames=2
TopWindow=True

 

here is a picture of the HTML code:

2126363342_Screenshot(36).thumb.png.e018d18fa90b33780abe56afc008dea7.png

I'm 100% sure like the test site there is the only one iframe I need to enter and leave. But I can't understand why it's not working. 

As always any help would be appreciated.  :) 

Link to comment
Share on other sites

On 10/7/2019 at 1:43 AM, Danp2 said:

@Letraindusoir The brackets are added by _WD_ExecuteScript automatically, so I would say that the first one is the better of the two attempts.

Both _WD_NewTab and _WD_GetElementFromPoint pass multiple parameters to _WD_ExecuteScript, so you may want to review those functions for other working examples.

Thank you, Dan! Notice that it's separated by quotation marks and commas into a string.

Link to comment
Share on other sites

I did a lot of testing and I found out that it is entering the iframe properly and is finding the element right (checked this by highlighting the element)

I believe it is not sending the variable data because of some hidden characters in the variable.

The length of the plain text is:  812

The length of the variable is: 819

Any hints/tips/ideas as to why the variable is 7 chars bigger?

I get the variable by reading in data from an email. I chop the email up with "StringSplit" a lot maybe some invisible chars are not getting chopped?    

Link to comment
Share on other sites

41 minutes ago, nooneclose said:

Any hints/tips/ideas as to why the variable is 7 chars bigger?

I get the variable by reading in data from an email. I chop the email up with "StringSplit" a lot maybe some invisible chars are not getting chopped?    

Hard to say since we can't test it. Have you examined the results from the Scite output panel? Make sure that you set

$_WD_DEBUG = $_WD_DEBUG_Info

so that you get max details output.

Link to comment
Share on other sites

I think I found the problem. Is there a special space char that Autoit cant handle? at the end of both string after stripping @CR, @LF, @TAB and @CRLF the only difference between the two string was that one had a different space char at the end. The "ASCII code" for that char is 32 which makes no sense to me why it causes the variable to fail to send. (if I copy the plain text of that same string it works just fine)  

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...