繁体   English   中英

我们如何在xpath中传递两个不同的参数?

[英]How do we pass two different parameters within xpath?

我们可以解析放在map文件中的xpath中的两个不同的参数,并在函数中调用它来使用java标识一个元素吗?

XPath的:

//table[@id='TemplateCreator']//td[contains(@id,'Template.1.2')]

在上面的xpath 1.2中是row.column值。 因此,当我继续时,我想将行和列作为参数传递。 我在我的代码中使用硬编码的xpath,如下所示:

int row = 1;
int column = 2;
driver.findelement(By.Xpath("//table[@id='TemplateCreator']//td[contains(@id,'Template."+row+"."+column+"')]");

但是,我想从Map文件中调用此xpath并将行和列值作为参数传递。 像这样的东西但是可以使用Java吗?

string template = //table[@id='TemplateCreator']//td[contains(@id,'Template.<identifier_row>.<identifier_column>')]
driver.findelement(By.Xpath(template+row+column); 

尝试如下:

 String template = "//table[@id='TemplateCreator']//td[contains(@id,'Template.%d.%d')]"; //read template from Map file
    int row=1;
    int column=1;
    String after = String.format(template, row, column);
    System.out.println("after replacing: " + after);

在Map文件中,存储模板如下:

//table[@id='TemplateCreator']//td[contains(@id,'Template.%d.%d')]

所以,稍后您可以使用String.format格式化字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM