Jump to content
Danp2

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

Share this post


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

 

Share this post


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

 

Share this post


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

Share this post


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

Share this post


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

Share this post


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

Share this post


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

 

Share this post


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

Share this post


Link to post
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.  :) 

Share this post


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

Share this post


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

Share this post


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

Share this post


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

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