将Java变量添加到xpath [英] Adding Java variable to xpath

查看:122
本文介绍了将Java变量添加到xpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将定义的Java String变量添加到xpath-expression?这是一些清楚的代码:

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();

xpath应该与变量newUser一起使用,但是我不知道如何.

The xpath should work with the variable newUser, but I don´t know how.

推荐答案

是的,当您在使用硒时选择Java作为编程语言时,您可以执行Java上逻辑上可能的所有事情.

Yes, when you choose Java as your programming language while working with selenium, you can perform all things that are logically possible in Java.

以您的示例为例,xpath是一个使用字符串参数的函数.因此,就像在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();

这篇关于将Java变量添加到xpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆