PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Saturday, July 9, 2022

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

 July 09, 2022     groovy, java, katalon, keyword, selenium     No comments   

Issue

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!


Solution

To click on element you can use following method:

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

To format a String according to passed parameter you can use this:

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

For the specific use like in your question the template can be defined like this:

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


Answered By - Prophet
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing