Is it possible to add a defined Java String variable to an xpath-expression? Here is some code to make it clear:
String newUser = "NewUser123";
driver.findElement(By.xpath("//td[normalize-space(text())=**newUser**]/a")).click();
The xpath should work with the variable newUser, but I don´t know how.
Yes, when you choose Java as your programming language while working with selenium, you can perform all things that are logically possible in Java.
Take your example, xpath is a function which takes string arguments. So Like in Java we concatenate multiple strings using +
. you can do the same thing here.
String newUser = "NewUser123";
driver.findElement(By.xpath("//td[normalize-space(text())='"+newUser+"']/a")).click();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With