Home > Enterprise >  How to Pass Random value in Webdriver Xpath each time it runs
How to Pass Random value in Webdriver Xpath each time it runs

Time:06-24

I want to click the following element but each time it changes the string value "28" to random number when run the program, used not disable as its date picker and dates button which is disabled/enabled while click so want to click on enables once

By.xpath("//button[@data-testid='date_of_birth-datepicker-day_"28" and not(@disabled)]")

CodePudding user response:

Your XPath is a string, so you can just process your Xpath like this :

random_int = (new Random()).nextInt(100); 
By.xpath("//button[@data-testid='date_of_birth-datepicker-day_" random_int " and not(@disabled)]");

You probably have to extract the maximum int from your page source code.

  • Related