How to click to the last checkbox

Hello everyone,
I would need to click automatically on the last checkbox of a list on my browser (less than 5 but variable), i.e. the oldest article so as to delete it with a subsequent click.
If i click record, ui.vision extrapolate this:
Command: Click, Target: xpath=//*[@id="manageads"]/ul/li[3]/div/article/div/div/input and it work,
if I put li[2] select only the second checkbox, how do I make it select the last checkbox (regardless of how many there are)?
Thank you

I created a solution to solve this problem

you must use storexpathcount and after you select the latest xpath with [n] with the number counted from storexpathcount

The result will be:
xpath=//*([@id=“manageads”]/ul/li[3]/div/article/div/div/input)[${Var}]

https://ui.vision/rpa/docs/selenium-ide/storexpathcount

newuserkantu thankyou,
i tried to use storexpathcount and enter in the “Target” this xpath=//*([@id=“manageads”]/ul/li[3]/div/article/div/div/input)[${Var}] but an error comes out: variable “VAR” is not defined .
How can I solve? What did I do wrong? Thank you

Read how work storexpathcount

After you must save value in variable and use it in xpath

https://ui.vision/rpa/docs/selenium-ide/storexpathcount

I tried to read but sorry I’m not a programmer, so it is difficult for me to understand.
I don’t understand how to save the variable and use it on xpatch.

Post url page and i create it for you, i need the url page

This is a web page that requires a name and password for access. Can I try to save the web page, save it on google drive and send it to you?

Try to save the page and i try to create macro code with saved page

Save page in html or htm please

the genre of the site is this, can the image be useful?

Without a page url i can not save the xpath

Try this code, it’s very hard to create macro code without access to the page

{
  "Name": "Checkbox",
  "CreationDate": "2020-8-10",
  "Commands": [
    {
      "Command": "storeXpathCount",
      "Target": "xpath=//*[@id=\"manageads\"]/ul/li[3]/div/article/div/div/input",
      "Value": "Var"
    },
    {
      "Command": "echo",
      "Target": "Latest Checkbox Is ${Var}",
      "Value": "#shownotification"
    },
    {
      "Command": "click",
      "Target": "xpath=(//*[@id=“manageads”]/ul/li[3]/div/article/div/div/input)[${Var}]",
      "Value": ""
    }
  ]
}

Thank you , this error comes out:
Line 2: Failed to execute 'evaluate' on 'Document': The string '//*[@id=\"manageads\"]/ul/li[3]/div/article/div/div/input' is not a valid XPath expression.
I send you the html of the page

This is the html

Thankyou

Try this code it automatically detect and click latest checkbox

If you solved click solution in my post thanks

{
  "Name": "Checkbox",
  "CreationDate": "2020-8-10",
  "Commands": [
    {
      "Command": "bringBrowserToForeground",
      "Target": "",
      "Value": ""
    },
    {
      "Command": "storeXpathCount",
      "Target": "xpath=//input[@type='checkbox']",
      "Value": "Var"
    },
    {
      "Command": "echo",
      "Target": "Latest Checkbox Is ${Var}",
      "Value": "#shownotification"
    },
    {
      "Command": "click",
      "Target": "xpath=(//input[@type='checkbox'])[${Var}]",
      "Value": ""
    }
  ]
}

Image

2 Likes

Uhau!
You are fantastic! Thank you! Also the expression bringBrowserToForeground, is another thing I didn’t know but was looking for.

1 Like

bringBrowserToForeground bring browser in front to see if macro works and I use echo with notification to know the result of command and check it

Just in case someone else comes along this, just remember there’s already an xtype selector for last child, last(). In most properly formatted HTML webpages you’ll be able to find way of using the last child of an overarching parent div to select the final element. For instance, this grabs the last list item of a dropdown with the id of “project-dropdown”, then searches for a link within it.

xpath=//*[@id=“project-dropdown”]/li[last()]/a

1 Like