2

My code snippet looks like this:

for(int i=1;i<=indexCount;i++){
        driver.findElement(By.xpath("//*[@id='assessmentTakerForm']/div/div/div/**div[i]**/div/label/input")).click();
        }

My goal is to get that int value 'i' inside that div[]. How can I make it work? Thanks in advance.

1 Answer 1

8

By following :

driver.findElement(By.xpath("//*[@id='assessmentTakerForm']/div/div/div/**div['"+ i +"']**/div/label/input")).click();
Sign up to request clarification or add additional context in comments.

1 Comment

clean way to do it (+1). However I would criticize OP for using this kinda Xpath : //*[@id='assessmentTakerForm']/div/div/div/**div[i]**/div/label/input

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.