![](/img/trans.png)
[英]Inheriting xpath string in Java using Selenium Webdriver and Cucumber
[英]Selenium Java Webdriver: Adding a string to an Xpath
我有下面的Java,我想在其中添加一个String 到语句中:
@and ("^I want to change fieldnumber \"([^\"]*)\" , remove whats inside and add the following text: \"([^\"]*)\"$")
public void testscenario12345(String number, String text) throws Throwable {
driver.findElement(By.xpath("//*[contains(@name,'template:view:<INSERT NUMBER STRING HERE>:item:view:1:item:')]")).clear();
driver.findElement(By.xpath("//*[contains(@name,'template:view:<INSERT NUMBER STRING HERE>:item:view:1:item:')]")).sendKeys(text);
如何在上面的代码段中添加数字字符串? 为了澄清,如果我在黄瓜中插入“ 4”,我希望驱动程序通过Xpath查找元素,其中@name包含template:view:4:item:view:1:item:
关于什么
driver.findElement(By.xpath("//*[contains(@name,\"template:view:" + number+ ":item:view:1:item:\")]")).clear();
您可能需要将数字设为const,这意味着:
public void testscenario12345(final String number, String text) throws Throwable {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.