Jump to content

Webdriver Salesforce unable to tick Checkbox


Recommended Posts

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:

Quote

--> IE.au3 T3.0-2 Warning from function _IEGetObjByName, $_IESTATUS_NoMatch (Name: myPage:myForm:oliListBlock:oliListTable:j_id36, Index: 0)
--> IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_InvalidDataType

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!

Edited by Langmeister
Link to post
Share on other sites

I don't know SF, but here are a few basic things you can look into --

  • Does the site use frames?
  • Are you sure that is the correct element name?
  • Does the element have an Id that you can use instead of the name?

You may want to post the element's HTML so that we can see for ourselves.

P.S. If you share your experience with the Webdriver UDF, then I'm sure that we can figure out how to get it working for you

Link to post
Share on other sites
On 7/3/2020 at 1:21 PM, Danp2 said:

I don't know SF, but here are a few basic things you can look into --

  • Does the site use frames?
  • Are you sure that is the correct element name?
  • Does the element have an Id that you can use instead of the name?

You may want to post the element's HTML so that we can see for ourselves.

P.S. If you share your experience with the Webdriver UDF, then I'm sure that we can figure out how to get it working for you

Thanks for the fast response, to your tips:

  • Don't know how to find that out, but guess so - what difference would that make?
  • Yes it is the correct element name, unfortunately it doesn't have any kind of id attached to it, just a parented table which i could try to adress

Anyways, if we get webdriver running it is probably going to work easier.

So I followed the guide which can be found in the Webdriver UDF Wiki and have put all the .au3 files (Json;Winhhtp;WD) in the includes folder of AutoIt as well as the chrome specific version of chromedriver in the above lying directory of AutoIt C:\Program Files (x86)\AutoIt3. 
Running wd_demo and choosing i.e. "Navigate" doesn't open Chrome but returns:  

Quote

_WD_IsLatestRelease: True
_WD_IsLatestRelease ==> Success
_WDStartup: OS:    WIN_10 WIN32_NT 17134 
_WDStartup: AutoIt:    3.3.14.5
_WDStartup: WD.au3:    0.3.0.3 (Up to date)
_WDStartup: WinHTTP:    1.6.4.1
_WDStartup: Driver:    C:\Program Files (x86)\AutoIt3\chromedriver.exe
_WDStartup: Params:    --log-path="C:\Program Files (x86)\AutoIt3\Include\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=WinHTTP request timed out before Webdriver...
__WD_Post ==> Send / Recv error: WinHTTP request timed out before Webdriver
_WD_CreateSession: WinHTTP request timed out before Webdriver
_WD_CreateSession ==> Webdriver Exception: HTTP status = 0
__WD_Delete: URL=HTTP://127.0.0.1:9515/session/
__WD_Delete: StatusCode=0; ResponseText=WinHTTP request timed out before Webdriver...
__WD_Delete ==> Webdriver Exception: WinHTTP request timed out before Webdriver
_WD_DeleteSession: WinHTTP request timed out before Webdriver
_WD_DeleteSession ==> Webdriver Exception: HTTP status = 0
>Exit code: 0    Time: 18.18
 

Already tried adding _WD_Option("Driver", "C:\Program Files (x86)\AutoIt3\chromedriver.exe") to the code but this doesn't seem to fix the issue.
 

For later usage, that is the elements html:

<input name="myPage:myForm:oliListBlock:oliListTable:j_id36" title="Toggle All Rows" onchange="A4J.AJAX.Submit('myPage:myForm',event,{'similarityGroupingId':'myPage:myForm:oliListBlock:oliListTable:j_id37','parameters':{'myPage:myForm:oliListBlock:oliListTable:j_id37':'myPage:myForm:oliListBlock:oliListTable:j_id37'} ,'status':'myPage:myForm:oliListBlock:rerenderStatus'} )" type="checkbox" checked="checked">

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

Please see the troubleshooting section of the wiki, found here.

Good news - it works. I installed the 1.6.4.2 version of WinHttp of your stated wiki, specified the location of my chromedriver (C: ..) and found another pain point which had to be fixed in advance. While I was figuring out how to get the code running my company has updated the chrome version. Luckily the chromedriver for 83.0.4103.39 works fine with 83.0.4103.97  too so that the following script works fine for me. Just opening Chrome, navigating to Google, opening a new tab with yahoo on it  and focussing back at Google again.

#include "wd_core.au3"
#include "wd_helper.au3"

Local $sDesiredCapabilities, $sSession
_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, "http://google.com")
    _WD_NewTab($sSession)
    _WD_Navigate($sSession, "http://yahoo.com")

    ConsoleWrite("URL=" & _WD_Action($sSession, 'url') & @CRLF)
    _WD_Attach($sSession, "google.com", "URL")

I'll try to apply it to my initial problem with Salesforce and if I need help I am going to hit the forum up again.

Link to post
Share on other sites

Well here I am once more. And it is the same issue as in the beginning except for slightly different code I am using now. It works fine with other pages, but not with SF. It seems that I have to get into the frame, but my quick and dirty research hasn't helped me at this point to figure out how.

Here ticking Lettuce works perfectly:

#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.w3.org/TR/wai-aria-practices/examples/checkbox/checkbox-2/checkbox-2.html")

_WD_GetSource($sSession)
_WD_LoadWait($sSession)

Local $check = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='cond1']")
_WD_ElementAction($sSession, $check, 'click')

But again applying it to SF it ends up with errors:

#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, "Corporate SF URL")


_WD_GetSource($sSession)
_WD_LoadWait($sSession)

;Not working from this point on
;---------------------------------------------------------------------------------------------------------------------
;Local $check = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='j_id36']")
;_WD_ElementAction($sSession, $check, 'click')

If you need further information let me know.

Link to post
Share on other sites

Btw these are the errors I'm receiving:
In short (no such element/Unable to locate element/no match)

__WD_Post: URL=HTTP://127.0.0.1:9515/session/fb9fe9a9afb92df26e6d16e7c029921c/element; $sData={"using":"xpath","value":"//input[@id='j_id36']"}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\...
_WD_FindElement: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//input[@id='j_id36']\"}\n  (Session info: chrome=83.0.4103.97)","stacktrace":"Backtrace:\n\tOrdinal0 [0x015A9563+2725219]\n\tOrdinal0 [0x014A8551+1672529]\n\tOrdinal0 [0x01390359+525145]\n\tOrdinal0 [0x01329755+104277]\n\tOrdinal0 [0x013453C0+218048]\n\tOrdinal0 [0x0133AAD0+174800]\n\tOrdinal0 [0x01343D7C+212348]\n\tOrdinal0 [0x0133A94B+174411]\n\tOrdinal0 [0x01322528+75048]\n\tOrdinal0 [0x013235A0+79264]\n\tOrdinal0 [0x01323539+79161]\n\tOrdinal0 [0x014BD607+1758727]\n\tGetHandleVerifier [0x016C6546+1050150]\n\tGetHandleVerifier [0x016C6291+1049457]\n\tGetHandleVerifier [0x016D10D7+1094071]\n\tGetHandleVerifier [0x016C6B46+1051686]\n\tOrdinal0 [0x014B5B06+1727238]\n\tOrdinal0 [0x014BEB7B+1764219]\n\tOrdinal0 [0x014BECE3+1764579]\n\tOrdinal0 [0x014D4C05+1854469]\n\tBaseThreadInitThunk [0x77148494+36]\n\tRtlAreBitsSet [0x77B04328+136]\n\tRtlAreBitsSet [0x77B042F8+88]\n"}}
_WD_FindElement ==> No match: HTTP status = 404
__WD_Post: URL=HTTP://127.0.0.1:9515/session/fb9fe9a9afb92df26e6d16e7c029921c/element//click; $sData={"id":""}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Element_id length is invalid\n  (Ses...
_WD_ElementAction: {"value":{"error":"no such element","message":"no such element: Element_id length is invalid\n  (Ses...
_WD_ElementAction ==> No match: {"value":{"error":"no such element","message":"no such element: Element_id length is invalid\n  (Session info: chrome=83.0.4103.97)","stacktrace":"Backtrace:\n\tOrdinal0 [0x015A9563+2725219]\n\tOrdinal0 [0x014A8551+1672529]\n\tOrdinal0 [0x01390359+525145]\n\tOrdinal0 [0x01329090+102544]\n\tOrdinal0 [0x0132A3BB+107451]\n\tOrdinal0 [0x013242EF+82671]\n\tOrdinal0 [0x0133AA9D+174749]\n\tOrdinal0 [0x013241F6+82422]\n\tOrdinal0 [0x0133ACE1+175329]\n\tOrdinal0 [0x01343D7C+212348]\n\tOrdinal0 [0x0133A94B+174411]\n\tOrdinal0 [0x01322528+75048]\n\tOrdinal0 [0x013235A0+79264]\n\tOrdinal0 [0x01323539+79161]\n\tOrdinal0 [0x014BD607+1758727]\n\tGetHandleVerifier [0x016C6546+1050150]\n\tGetHandleVerifier [0x016C6291+1049457]\n\tGetHandleVerifier [0x016D10D7+1094071]\n\tGetHandleVerifier [0x016C6B46+1051686]\n\tOrdinal0 [0x014B5B06+1727238]\n\tOrdinal0 [0x014BEB7B+1764219]\n\tOrdinal0 [0x014BECE3+1764579]\n\tOrdinal0 [0x014D4C05+1854469]\n\tBaseThreadInitThunk [0x77148494+36]\n\tRtlAreBitsSet [0x77B04328+136]\n\tRtlAreBitsSet [0x77B042F8+88]\n"}}

 

Link to post
Share on other sites
43 minutes ago, Langmeister said:

_WD_GetSource($sSession)

You had this in both of your examples. It is unnecessary unless you need to access the raw source. In that case, you would store the result in a variable.

46 minutes ago, Langmeister said:

;Not working from this point on

Again, I don't know SF, but if the site uses frames, then you need to switch to the correct one before the element can be located. Have you looked at the DemoFrames function in wd_demo.au3 for an example of how this should work?

Also, I would suggest that you take a look at the ChroPath extension, which can possible help you identify the correct xpath for a given element.

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

You had this in both of your examples. It is unnecessary unless you need to access the raw source. In that case, you would store the result in a variable.

Again, I don't know SF, but if the site uses frames, then you need to switch to the correct one before the element can be located. Have you looked at the DemoFrames function in wd_demo.au3 for an example of how this should work?

Also, I would suggest that you take a look at the ChroPath extension, which can possible help you identify the correct xpath for a given element.

Ok I will delete the line with Getsource. In the meantime I found out that SF is definetly using Frames which made it not working the easy way. I tried ChroPath but unfortunately it works with every other website except for SF. I am convinced that this doesn't take much more than the following code that is similar to what I want. Here it navigates to the website and clicks onto "Updating for Mobile" within the Iframe.

#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, "http://allwebco-templates.com/support/S_script_IFrame.htm")
ConsoleWrite("Frames=" & _WD_GetFrameCount($sSession) & @CRLF)
ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[2]")
_WD_FrameEnter($sSession, $sElement)
Sleep(5000)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html[1]/body[1]/div[1]/div[8]/div[1]/div[1]/a[1]")
_WD_ElementAction($sSession, $sElement, 'click')

You said I need to switch to the correct frame, but how do I adress the following  XPath like the $sElement in "//iframe[2]
Like is it possible to use the ID "sectioncontent-1499" for that?

;XPath According to Chrome
//*[@id="sectionContent-1499"]/div/slot/force-record-layout-row/slot/force-record-layout-item/div/div/div/span/slot[2]/force-aloha-page/div/iframe

;FUll XPath according to Chrome
/html/body/div[4]/div[1]/section/div/div/div[1]/div[2]/div/one-record-home-flexipage2/forcegenerated-flexipage_opportunity_record_page1_opportunity__view_js/flexipage-record-page-decorator/div/slot/flexipage-record-home-with-subheader-template-desktop2/div/div[3]/div[1]/slot/slot/flexipage-component2/force-progressive-renderer/slot/slot/flexipage-tabset2/div/lightning-tabset/div/slot/slot/slot/flexipage-tab2[2]/slot/flexipage-component2/force-progressive-renderer/slot/slot/records-lwc-detail-panel/records-base-record-form/div/div/div/records-record-layout-event-broker/slot/records-lwc-record-layout/forcegenerated-detailpanel_opportunity___012b0000000cw6kaae___full___view___recordlayout2/force-record-layout-block/slot/force-record-layout-section[20]/div/div/div/slot/force-record-layout-row/slot/force-record-layout-item/div/div/div/span/slot[2]/force-aloha-page/div/iframe

;The copied element from html
<iframe force-alohapage_alohapage="" height="500px" width="100%" scrolling="no" allowtransparency="true" name="vfFrameId_1594192229873" title="accessibility title" allowfullscreen="true" lang="en-US" allow="geolocation *; microphone *; camera *"></iframe>

 

Link to post
Share on other sites

@Danp2 The demo you suggested is this:

Local $sElement

    _WD_Navigate($sSession, "https://www.w3schools.com/tags/tryit.asp?filename=tryhtml_frame_cols")
    ConsoleWrite("Frames=" & _WD_GetFrameCount($sSession) & @CRLF)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)
    $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='iframeResult']")
    _WD_FrameEnter($sSession, $sElement)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)
    _WD_FrameLeave($sSession)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)

Adapting it to another website looks like this for me:

#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.w3schools.com/html/html_iframe.asp")
    ConsoleWrite("Frames=" & _WD_GetFrameCount($sSession) & @CRLF)
    ConsoleWrite("TopWindow=" & _WD_IsWindowTop($sSession) & @CRLF)
   $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='main']")
    _WD_FrameEnter($sSession, $sElement)
    Sleep(5000)
$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "/html/body/div[4]/div/div[1]/a[2]")
_WD_ElementAction($sSession, $sElement, 'click')

It opens the website and clicks on the home button of the website to have smth to click on.
This results in these responds:

__WD_Post: URL=HTTP://127.0.0.1:9515/session/7fc66e79c512e2c95360b95f5d1e5886/element; $sData={"using":"xpath","value":"//iframe[@id='main']"}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\...
_WD_FindElement: {"value":{"error":"no such element","message":"no such element: Unable to locate element: {\"method\":\"xpath\",\"selector\":\"//iframe[@id='main']\"}\n  (Session info: chrome=83.0.4103.97)","stacktrace":"Backtrace:\n\tOrdinal0 [0x00AF9563+2725219]\n\tOrdinal0 [0x009F8551+1672529]\n\tOrdinal0 [0x008E0359+525145]\n\tOrdinal0 [0x00879755+104277]\n\tOrdinal0 [0x008953C0+218048]\n\tOrdinal0 [0x0088AAD0+174800]\n\tOrdinal0 [0x00893D7C+212348]\n\tOrdinal0 [0x0088A94B+174411]\n\tOrdinal0 [0x00872528+75048]\n\tOrdinal0 [0x008735A0+79264]\n\tOrdinal0 [0x00873539+79161]\n\tOrdinal0 [0x00A0D607+1758727]\n\tGetHandleVerifier [0x00C16546+1050150]\n\tGetHandleVerifier [0x00C16291+1049457]\n\tGetHandleVerifier [0x00C210D7+1094071]\n\tGetHandleVerifier [0x00C16B46+1051686]\n\tOrdinal0 [0x00A05B06+1727238]\n\tOrdinal0 [0x00A0EB7B+1764219]\n\tOrdinal0 [0x00A0ECE3+1764579]\n\tOrdinal0 [0x00A24C05+1854469]\n\tBaseThreadInitThunk [0x769E8494+36]\n\tRtlAreBitsSet [0x77A84328+136]\n\tRtlAreBitsSet [0x77A842F8+88]\n"}}
_WD_FindElement ==> No match: HTTP status = 404
__WD_Post: URL=HTTP://127.0.0.1:9515/session/7fc66e79c512e2c95360b95f5d1e5886/frame; $sData={"id":{"element-6066-11e4-a52e-4f735466cecf":""}}
__WD_Post: StatusCode=404; ResponseText={"value":{"error":"no such element","message":"no such element: Element_id length is invalid\n  (Ses...
_WD_Window: {"value":{"error":"no such element","message":"no such element: Element_id length is invalid\n  (Ses...
_WD_Window ==> No match: HTTP status = 404
_WD_FrameEnter ==> Webdriver Exception
__WD_Post: URL=HTTP://127.0.0.1:9515/session/7fc66e79c512e2c95360b95f5d1e5886/element; $sData={"using":"xpath","value":"/html/body/div[4]/div/div[1]/a[2]"}
__WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"3f1fba85-91a0-413f-9c68-13524d76d902"}}...
_WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"3f1fba85-91a0-413f-9c68-13524d76d902"}}
__WD_Post: URL=HTTP://127.0.0.1:9515/session/7fc66e79c512e2c95360b95f5d1e5886/element/3f1fba85-91a0-413f-9c68-13524d76d902/click; $sData={"id":"3f1fba85-91a0-413f-9c68-13524d76d902"}
__WD_Post: StatusCode=200; ResponseText={"value":null}...
_WD_ElementAction: {"value":null}...

Leaving the below two lines out erases the two 404 errors and still clicks, but again applying it only using the full xpath as $sElement doesn't work with SF.

$sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//iframe[@id='main']")
    _WD_FrameEnter($sSession, $sElement)

Maybe @Bert or @BigDaddyO know how to apply this to Salesforce.
In Specific I want to adress the Offerings (OLI) which can be found within an iFrame.

Edited by Langmeister
Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By corvo
      Hello!

      I've been trying to launch chrome through WD,  but for some reason, the user profile is not working, it just opens up the chrome window with the "temp" user. I've also made sure that the user profile path is correct by using "chrome://version". 
      Here is what I've got so far:
      #include "wd_helper.au3" #include "wd_capabilities.au3" #include "wd_core.au3" SetupChrome() _WD_CapabilitiesStartup() Local $sCapabilities = _WD_CapabilitiesGet() $sSession = _WD_CreateSession($sCapabilities) _WD_Navigate($sSession, "https://www.google.com") Func SetupChrome() _WD_Option('Driver', 'chromedriver.exe') _WD_Option('Port', 9515) _WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') _WD_Option('DriverParams', '--marionette-port 2828') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"goog:chromeOptions": {"w3c": true, "args":["--user-data-dir=C:\\Users\\' & @UserName & '\\AppData\\Local\\Google\\Chrome\\User Data\\", "--profile-directory=Profile 2"]}}}}' $_WD_DEBUG = $_WD_DEBUG_None ; You could also use $_WD_DEBUG_Error EndFunc  
      Thanks in advance!
       
    • By ThomasBennett
      Good morning, everyone, 
      I have had very good luck with using _WD_ElementActionEx 'CLICKANDHOLD'. What would be the best practice with dragging and dropping web elements? I would prefer to not to have to use any dragging and dropping but I haven't figured out a way to change the order the elements are displayed programmatically. 
      I have a list of elements that are drag and drop. These elements in code are using <UL></UL> for the entire list and the actual web elements that are being manipulated are in <LI></LI> tags. These do not look like a bulleted list but that is the code that is being used. I've spoken with the web developer and there isn't any hot keys or keyboard commands that can be used to move these elements.
      I know where the new and original web element appears and can select them using the _WD_WaitElement and _WD_FindElement combo. I can find the number of items in the list by looking at the code; I haven't started pulling the values out just yet. I am trying to figure out if there is a place to change the listed order.
      Using the 'CLICKANDHOLD' feature as part of _WD_ElementActionEx does work and I know more or less where I need to drop it the new web element; the problem I am having is scrolling exactly to where I need the new web element dropped. It should be dropped beneath the original web element. 
      What's the best method to output the number of children associated with the <UL></UL>? I am guessing that _WD_ElementActionEx 'CHILDCOUNT' would be it; but I haven't figured out how to get the call to output in a msgbox or in the console. 
      #cs ---------------------------------------------------------------- Name ..........: Please Note!.au3 Description ...: To be used to add new lessons to existing playlists and to update the pre-existing lesson with the Please Note! PowerPoint SciTE 32-bit ..: Version 4.4.6 Author(s) .....: Thomas E. Bennett Date ..........: 20220929 Recommended Reading / Requirements https://www.autoitscript.com/forum/topic/191990-webdriver-udf-w3c-compliant-version-01162021/#comments https://www.autoitscript.com/wiki/WebDriver https://www.autoitscript.com/wiki/WebDriver#Installation https://www.autoitscript.com/wiki/Adding_UDFs_to_AutoIt_and_SciTE https://www.autoitscript.com/autoit3/docs/intro/running.htm#CommandLine wd_core.au3 wd_helper.au3 From wd_core.au3 Global Const $_WD_LOCATOR_ByCSSSelector = "css selector" Global Const $_WD_LOCATOR_ByXPath = "xpath" Global Const $_WD_LOCATOR_ByLinkText = "link text" Global Const $_WD_LOCATOR_ByPartialLinkText = "partial link text" Global Const $_WD_LOCATOR_ByTagName = "tag name" #ce ---------------------------------------------------------------- #include "wd_core.au3" #include "wd_helper.au3" #include <MsgBoxConstants.au3> #include <Excel.au3> #include <AutoItConstants.au3> Local $sDesiredCapabilities, $sSession, $sElement ; Create application object and open an example workbook Local $oExcel = _Excel_Open() If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error creating the Excel application object." & @CRLF & "@error = " & @error & ", @extended = " & @extended) Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\{PRIVACY}.xlsx") If @error Then MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example", "Error opening workbook '" & @ScriptDir & "\{PRIVACY}.xlsx'." & @CRLF & "@error = " & @error & ", @extended = " & @extended) _Excel_Close($oExcel) Exit EndIf ; Read data from a single cell on the active sheet of the specified workbook ;Local $sResult = _Excel_RangeRead($oWorkbook, Default, "A1") ;If @error Then Exit MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 1", "Error reading from workbook." & @CRLF & "@error = " & @error & ", @extended = " & @extended) ;MsgBox($MB_SYSTEMMODAL, "Excel UDF: _Excel_RangeRead Example 1", "Data successfully read." & @CRLF & "Value of cell A1: " & $sResult) SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) Sleep (15000) Local $aResult = _Excel_RangeRead($oWorkbook, Default, "A16:E16") For $i = 0 To UBound($aResult, 1) - 1 ;ConsoleWrite("========= Start Row =========" & @CRLF) ;ConsoleWrite($aResult[$i][0] & @CRLF) ; Column A -- Course Playlist Number ;ConsoleWrite($aResult[$i][1] & @CRLF) ; Column B -- Course Playlist Title ;ConsoleWrite($aResult[$i][2] & @CRLF) ; Column C -- Original Lesson Title ;ConsoleWrite($aResult[$i][3] & @CRLF) ; Column D -- Updated Lesson Number ;ConsoleWrite($aResult[$i][4] & @CRLF) ; Column E -- Updated Lesson Title ;ConsoleWrite("========= End Row =========" & @CRLF & @CRLF) _WD_Navigate($sSession, "{PRIVACY}" & $aResult[$i][0]) _WD_LoadWait($sSession, 2000) ; Find the Available Lessons search box and enter the appropriate value _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='titleSearch']") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='titleSearch']") ; Click the Sign in button _WD_ElementAction($sSession, $sElement, 'value', $aResult[$i][3]) Send("{Enter}") ; Find the correct "Add" hyperlink _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//span[text()='" & $aResult[$i][4] & "']/following-sibling::div") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[text()='" & $aResult[$i][4] & "']/following-sibling::div") ; Click the "Add" hyperlink _WD_ElementAction($sSession, $sElement, 'click') ; Number of Child Elements _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']") _WD_ElementActionEx($sSession, $sElement, 'CHILDCOUNT') Exit ; Click and Hold the appropriate element _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']//span[@class='item-description' and text()='" & $aResult[$i][4] & "']/parent::li") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']//span[@class='item-description' and text()='" & $aResult[$i][4] & "']/parent::li") _WD_ElementActionEx($sSession, $sElement, 'clickandhold', 0, 0, 0, 10000) ; Hover the appropriate element _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']//span[@class='item-description' and text()='" & $aResult[$i][4] & "']/following-sibling::a") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//ul[@id='selected-items']//span[@class='item-description' and text()='" & $aResult[$i][4] & "']/following-sibling::a") _WD_ElementActionEx($sSession, $sElement, 'HOVER') Exit Next Exit _WD_DeleteSession($sSession) _WD_Shutdown() Exit Func SetupChrome() ; Google Chrome _WD_Option('Driver', "C:\Users\thomas.bennett\Desktop\AutoIt\include\chromedriver.exe") _WD_Option('Port', 9515) ;_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"unhandledPromptBehavior": "ignore", ' & _ '"goog:chromeOptions": {"w3c": true, "excludeSwitches": ["enable-automation"], "useAutomationExtension": false, ' & _ '"prefs": {"credentials_enable_service": false},' & _ '"args": ["start-maximized"] }}}}' EndFunc Console Output
      >"C:\Program Files (x86)\AutoIt3\SciTE\..\AutoIt3.exe" "C:\Program Files (x86)\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.au3" /run /prod /ErrorStdOut /in "C:\Users\thomas.bennett\Desktop\AutoIt\Please Note!\Please Note!.au3" /UserParams +>09:22:40 Starting AutoIt3Wrapper (21.316.1639.1) from:SciTE.exe (4.4.6.0) Keyboard:00000409 OS:WIN_10/2009 CPU:X64 OS:X64 Environment(Language:0409) CodePage:0 utf8.auto.check:4 +> SciTEDir => C:\Program Files (x86)\AutoIt3\SciTE UserDir => C:\Users\thomas.bennett\AppData\Local\AutoIt v3\SciTE\AutoIt3Wrapper SCITE_USERHOME => C:\Users\thomas.bennett\AppData\Local\AutoIt v3\SciTE >Running AU3Check (3.3.14.5) from:C:\Program Files (x86)\AutoIt3 input:C:\Users\thomas.bennett\Desktop\AutoIt\Please Note!\Please Note!.au3 +>09:22:40 AU3Check ended.rc:0 >Running:(3.3.14.5):C:\Program Files (x86)\AutoIt3\autoit3.exe "C:\Users\thomas.bennett\Desktop\AutoIt\Please Note!\Please Note!.au3" +>Setting Hotkeys...--> Press Ctrl+Alt+Break to Restart or Ctrl+BREAK to Stop. _WD_Option ==> Success [0] : Parameters: Option=Driver Value=C:\Users\thomas.bennett\Desktop\AutoIt\include\chromedriver.exe _WD_Option ==> Success [0] : Parameters: Option=Port Value=9515 _WD_IsLatestRelease ==> Success [0] : True _WD_Startup: OS: WIN_10 WIN32_NT 22000 _WD_Startup: AutoIt: 3.3.14.5 _WD_Startup: Webdriver UDF: 0.10.1 (Up to date) _WD_Startup: WinHTTP: 1.6.4.2 _WD_Startup: Driver: C:\Users\thomas.bennett\Desktop\AutoIt\include\chromedriver.exe (32 Bit) _WD_Startup: Params: _WD_Startup: Port: 9515 _WD_Startup: Command: "C:\Users\thomas.bennett\Desktop\AutoIt\include\chromedriver.exe" _WD_Startup ==> Success [0] __WD_Post ==> Success [0] : HTTP status = 200 _WD_CreateSession ==> Success [0] : 2542b35e47b8f9b2558cd92ad1418811 __WD_Post ==> Success [0] : HTTP status = 200 _WD_Navigate ==> Success [0] : Parameters: URL={PRIVACY} _WD_LoadWait ==> Success [0] : Parameters: Delay=2000 Timeout=Default Element=Default _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='Username'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='Username'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=value Option=<masked> _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='Password'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='Password'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=value Option=<masked> _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@value='Sign In'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@value='Sign In'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=click Option=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_Navigate ==> Success [0] : Parameters: URL={PRIVACY} _WD_LoadWait ==> Success [0] : Parameters: Delay=2000 Timeout=Default Element=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_Navigate ==> Success [0] : Parameters: URL={PRIVACY} _WD_LoadWait ==> Success [0] : Parameters: Delay=2000 Timeout=Default Element=Default _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='titleSearch'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//input[@id='titleSearch'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ElementAction ==> Success [0] : Parameters: Command=value Option=<masked> _WD_WaitElement ==> Timeout [7] : Parameters: Strategy=xpath Selector=//span[text()='{PRIVACY}']/following-sibling::div Delay=Default Timeout=Default Options=Default __WD_Post ==> No match [8] : HTTP status = 404 _WD_FindElement ==> No match [8] : Parameters: Strategy=xpath Selector=//span[text()='{PRIVACY}']/following-sibling::div StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> No match [8] : HTTP status = 404 _WD_ElementAction ==> No match [8] : Parameters: Command=click Option=Default _WD_WaitElement ==> Success [0] : Parameters: Strategy=xpath Selector=//ul[@id='selected-items'] Delay=Default Timeout=Default Options=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_FindElement ==> Success [0] : Parameters: Strategy=xpath Selector=//ul[@id='selected-items'] StartNodeID=Default Multiple=Default ShadowRoot=Default __WD_Post ==> Success [0] : HTTP status = 200 _WD_ExecuteScript ==> Success [0] _WD_ElementActionEx ==> Success [0] : Parameters: Element=21c01052-8b86-4058-b8f6-d9dfa750f9ee Command=CHILDCOUNT XOffset=Default YOffset=Default Button=Default HoldDelay=Default Modifier=Default +>09:23:20 AutoIt3.exe ended.rc:0 +>09:23:20 AutoIt3Wrapper Finished. >Exit code: 0 Time: 40.88  

      My thought is once AutoIt knows how many child elements there are; I am hoping that there would be a way to change the sort or priority order that the <LI></LI>'s are shown in. 
      Thank you for your time and efforts on this and as I progress I'll update this topic, 




      Thomas 
    • By ThomasBennett
      #cs ---------------------------------------------------------------- Name ..........: ignore.au3 Description ...: Testing _WD_HighlightElements SciTE 32-bit ..: Version 4.4.6 Author(s) .....: Thomas E. Bennett Date ..........: 20220929 Recommended Reading / Requirements https://www.autoitscript.com/forum/topic/191990-webdriver-udf-w3c-compliant-version-01162021/#comments https://www.autoitscript.com/wiki/WebDriver https://www.autoitscript.com/wiki/WebDriver#Installation https://www.autoitscript.com/wiki/Adding_UDFs_to_AutoIt_and_SciTE https://www.autoitscript.com/autoit3/docs/intro/running.htm#CommandLine wd_core.au3 wd_helper.au3 From wd_core.au3 Global Const $_WD_LOCATOR_ByCSSSelector = "css selector" Global Const $_WD_LOCATOR_ByXPath = "xpath" Global Const $_WD_LOCATOR_ByLinkText = "link text" Global Const $_WD_LOCATOR_ByPartialLinkText = "partial link text" Global Const $_WD_LOCATOR_ByTagName = "tag name" #ce ---------------------------------------------------------------- #include "wd_core.au3" #include "wd_helper.au3" #include "wd_cdp.au3" #include "wd_capabilities.au3" #include <MsgBoxConstants.au3> Local $sDesiredCapabilities, $sElement, $sSession Func SetupChrome() ; Google Chrome _WD_Option('Driver', @ScriptDir & "\include\chromedriver.exe") _WD_Option('Port', 9515) ;_WD_Option('DriverParams', '--verbose --log-path="' & @ScriptDir & '\chrome.log"') $sDesiredCapabilities = '{"capabilities": {"alwaysMatch": {"unhandledPromptBehavior": "ignore", ' & _ '"goog:chromeOptions": {"w3c": true, "excludeSwitches": ["enable-automation"], "useAutomationExtension": false, ' & _ '"prefs": {"credentials_enable_service": false},' & _ '"args": ["start-maximized"] }}}}' EndFunc SetupChrome() _WD_Startup() $sSession = _WD_CreateSession($sDesiredCapabilities) Sleep (15000) ; DuckDuckGo _WD_Navigate($sSession, "https://duckduckgo.com/") _WD_LoadWait($sSession, 2000) ; Find the Search field _WD_WaitElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='search_form_input_homepage']") $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//input[@id='search_form_input_homepage']") ; Highlight the Search field _WD_HighlightElements($sSession, $sElement, 3) MsgBox(0,"","") Exit ;this is here on purpose _WD_DeleteSession($sSession) _WD_Shutdown() Exit Good evening, everyone, 
      I am trying to get any element to highlight using the _WD_HighlightElements function; I've tried different elements and for a time I thought maybe because I am working in Windows 11 so I switched back to Windows 10 same issue; I can't get the found element to highlight. What am I doing incorrectly?
      Console Output _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"0e212d4f-8437-42a0-a56a-bc8694fe6e66"}} _WD_WaitElement ==> Success __WD_Post: URL=HTTP://127.0.0.1:9515/session/0e05f8ea99dba06bb84908b0b46fe881/element; $sData={"using":"xpath","value":"//input[@id='search_form_input_homepage']"} __WD_Post: StatusCode=200; ResponseText={"value":{"element-6066-11e4-a52e-4f735466cecf":"0e212d4f-8437-42a0-a56a-bc8694fe6e66"}}... _WD_FindElement: {"value":{"element-6066-11e4-a52e-4f735466cecf":"0e212d4f-8437-42a0-a56a-bc8694fe6e66"}} Thank you for your time on this,




      Thomas E. Bennett
    • By SkysLastChance
      I am having trouble finding a good way to click these "button" below. 

      I only need to be able to click them when they have both yes/no. Otherwise I don't have to worry about them. For instance if they looked like this I would NOT have worry about clicking them and can just ignore them all togheter.(Below Picture)

      The problem is as mentioned in the title, all of the ID's  are dynamic. (Classes too)

      Here is what it looks like if yes is already selected.

      This is what I was using to select the the button. However, I need to know if the button has already been clicked/selected or not.
      _WD_LoadWait($sSession) $sElement = _WD_FindElement($sSession, $_WD_LOCATOR_ByXPath, "//span[text() = 'Offered access to electronic health information?']") Sleep(1000) _WD_ElementAction($sSession, $sElement, 'click') Sleep(500) _WD_Action($sSession, "actions", $sActionTab) Sleep(500) _WD_Action($sSession, "actions", $sActionEnter) Is there a way I can get the count of spans in the span class-"s_636" by tabbing over to the button? I am hoping someone might have some ideas on what I can try.
      Unfortunally, The site is for work so giving the site wont do any good. 
    • By ThomasBennett
      Good morning, everyone, 
      I am using WebDriver with ChromeDriver version 105.0.5195.52
      I have the script almost completed; this is going to be used as a wait / pause until the file has completed uploading. I was able to find where the value: "C:\\fakepath\\Vladimir Harkonnen.jpg" is stored. I am trying to figure out how to read this value. This is part of an <input type="file"> element. Reading / finding the value would be the trigger to allow the script to continue. I don't know very much but I feel like I am either not using WebDriver correctly or possibly it won't be able to help me with what I am trying to do.
      Please see the attached screenshot. 
      Thank you for your time, experience, and patience with me,




      Thomas Bennett
       

×
×
  • Create New...