Syntax for Abs XPath

Hi all,

I am in the process of learning the basic syntax for this software, and im having difficulty finding an example of the usage of the attribute Abs XPath for interacting with a browser element.
Ive been searching through some good posts, such as the mini-guide from burque505, but havent found what im looking for.

  • Do I us the start format, ....domcontainer{<{<{<SelectorSeparator>}>}>}uia3://…?
  • How would I integrate ‘/html[1]/body[1]/app-root[1]/div[2]/app-rpa1[1]/div[1]/div[2]/form[1]/div[1]/div[1]/rpa1-field[1]/div[1]/input[1]’?

Thanks

1 Like

Hi @morbid42, you might try this. I’m using a relative XPath, but I’ll try it with an absolute path also.

WebAutomation.LaunchChrome          Url: "https://forum.robin-language.org/t/syntax-for-abs-xpath/617" \
                                    WindowState:WebAutomation.BrowserWindowState.Normal \
                                    ClearCache:False \
                                    ClearCookies:False \
                                    BrowserInstance=> Browser

wait 3

WebAutomation.DataExtraction.GetDetailsOfElement    BrowserInstance: Browser  \
                                                    Control: 'domcontainer{<{<{<SelectorSeparator>}>}>}uia3:// div[class="cooked"]' \
                                                    AttributeName:'Own Text' \
                                                    AttributeValue=> AttributeValue

Console.Write                       Message: AttributeValue

wait 5

WebAutomation.CloseWebBrowser       BrowserInstance: Browser 

Regards,
burque505

2 Likes

@morbid42, I haven’t had any luck with absolute XPath and ‘WebAutomation.DataExtraction.GetDetailsOfElement’, but the following works with Javascript:

WebAutomation.LaunchFirefox      Url: 'https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_checkbox' \
                                WindowState:WebAutomation.BrowserWindowState.Normal \
                                ClearCache:True \
                                ClearCookies:False \
                                BrowserInstance=> Browser
wait 2

WebAutomation.ExecuteJavascript BrowserInstance: Browser \
                                Javascript:'''function ExecuteScript() {
                                var myAlert = document.evaluate('/html[1]/body[1]/div[7]/div[3]/div[1]/div[1]/div[1]/div[6]/div[1]/div[1]/div[1]/div[1]/div[5]/pre[5]/span[1]/span[4]', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerHTML;
                                alert(myAlert);}''' \
                                Result=> Result
                                
                                
# /html[1]/body[1]/div[7]/div[3]/div[1]/div[1]/div[1]/div[6]/div[1]/div[1]/div[1]/div[1]/div[5]/pre[5]/span[1]/span[4]

# document.evaluate('Your_XPATH', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerHTML;
# https://coderwall.com/p/u2amea/javascript-get-element-by-xpath

Sorry I haven’t broken down the Javascript call into shorter lines. By the way, the post here was a big help.

EDIT: This code is probably harder to read, but maybe easier to modify.

set myXPath to "/html[1]/body[1]/div[7]/div[3]/div[1]/div[1]/div[1]/div[6]/div[1]/div[1]/div[1]/div[1]/div[5]/pre[5]/span[1]/span[4]"

set parmVar to "document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.innerHTML"

WebAutomation.LaunchFirefox     Url: 'https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_input_type_checkbox' \
                                WindowState:WebAutomation.BrowserWindowState.Normal \
                                ClearCache:True \
                                ClearCookies:False \
                                BrowserInstance=> Browser
wait 2

WebAutomation.ExecuteJavascript BrowserInstance: Browser \
                                Javascript: """
                                function ExecuteScript() {
                                var myAlert = document.evaluate(`""" + myXPath + """`, """ + parmVar + """;
                                alert(myAlert);}""" \
                                Result=> Result

Regards,
burque505

1 Like

Hi burque505,

Thanks for spending your time having a look at this, you’ve gone to great effort and your two posts knowledge share will keep me occupied tonight.

I havent fully looked at the WebAutomation extensions - youve given me a gentle nudge to look at this in more depth. I like what i see so far - I can see myself spending alot of time with Robin.

Thanks

1 Like

I wish you the best of luck with it, @morbid42, and look forward to your results.
Regards,
burque505