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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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
 Share

×
×
  • Create New...