1

enter image description hereHello I just start using selenium with java framework :

I have this case : I need to count all the check boxes in my view which contains multiple pages (1,2,3) and in each web page i have a bunch of check boxes with the same xpath with different number see the exemple below:

xpath fir the second checkbox in page 1 : "//*[@id='mat-checkbox-2']/label/div" xpath fir the second checkbox in page 40 : //*[@id="mat-checkbox-57"]/label/div"

driver.findElements(By.xpath("//*[@id='mat-checkbox-" + regex +"']/label/div")).size()

How can I count all the present checkboxes in my current view without refering to the order number ?

1 Answer 1

1

You can use partial id in the xpath with contains or starts-with

"//*[starts-with(@id,'mat-checkbox')]/label/div"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.