如何构建自定义定位器的By.xpath方法?
我正在尝试使用 By 方法来设置页面对象类中的变量。我的场景之一要求表根据用户输入使用自定义值进行循环。
所以我不得不编写定制的xpath。但是,当尝试编写以适应 By 方法时,我陷入了如何处理迭代数的困境。例如,下面显示了我的定位器:
By test = By.xpath("//thead/tr[1]/th[" + i + "]"));
即使声明了 int i ;
,它也会显示声明中“i”值的错误。
请让我知道如何处理这个问题。
I'm trying to use the By method for the setting of variables in my page object class. One of my scenario requires the table to loop with customized value based on user input.
So I had to write customized xpath. But when trying to write to fit into the By method i'm stuck on how to handle the iteration number. For example the below shows my locator:
By test = By.xpath("//thead/tr[1]/th[" + i + "]"));
It shows error for the "i" value in the declaration, even if int i ;
is declared.
Please let me know how to handle this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于变量
i
是整数类型,因此在构造有效的<之前,您必须将其转换为字符串
href="https://stackoverflow.com/a/48376890/7429447">定位器策略如下:As the variable
i
is of type integer, you have to convert it into astring
before constructing the effective locator strategy as follows: