Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add the output to xpath

I have list of arrays from which I am picking up a random one. I can print the random output. How to pass the output as xpath value??

String[] Category = {"abc", "abc", "abc", "abc", "abc", "abc", "abc"};

    Random random = new Random();
    int index = random.nextInt(Category.length);
    System.out.println(Category[index]);
    driver.findElement(By.xpath("//*[@name='\"${Category[index]}\"']")).click();
like image 655
Arun Kumar Avatar asked Oct 30 '22 03:10

Arun Kumar


1 Answers

Try this one.

String xpath= "//*[@name='" + Category[index] + "']";   
driver.findElement(By.xpath(xpath)).click();
like image 98
Gangaraju Avatar answered Nov 15 '22 03:11

Gangaraju