如何使用 Katalon 在 Selenium 中通过 XPath 动态查找 Web 元素

How to dynamically find web element by XPath in Selenium using Katalon

driver.findElement(By.xpath("//*[contains(text(),'"+ ProjectName +"')]")).click();

I tried to use this code to find web element dynamically, but when I tried to call it on my test case seems that it cannot have an input value since this code is a part of my custom keyword code. Can someone help me try to find a way on how to do it. Thank you very much!

要单击元素,您可以使用以下方法:

public void clickOnElement(String xpath) {
    driver.findElement(By.xpath(xpath)).click();
}

要根据传递的参数格式化字符串,您可以使用:

public String stringFormat(String template, String parameter){
    return String.format(template,parameter);
}

对于您问题中的特定用途,template 可以这样定义:

String elementTextTmplt = "//*[contains(text(),'%s')]"