xpath identification Dynamic value passing
14,016
Try to use the following snippet to pass values at run time
public void portfolioRenewalSearch(String portfolioId) throws Exception {
try {
driver.findElement(By.xpath("//input[@accesskey="+portfolioId+"]"))
.click();
} catch (AssertionError Ae) {
Ae.printStackTrace();
}
}
Author by
Prabu
Automation Test Engineer Selenium WebDriver Katalon Studio Java / Groovy
Updated on June 04, 2022Comments
-
Prabu about 2 years
the xpath
driver.findElement(By.xpath("//input[@accesskey='9']"));
how cound we pass the Dynamic value in the accesskey Attribute, because the accesskey Attribute assign with any integer
so i get that id from database and try to pass that id in the accesskey attribute how using java?
Html code
td style="width: 5%;"> <input type="checkbox" data-bind="attr: { accesskey: Id }" accesskey="6"> </td> <td style="width: 5%;"> <input type="checkbox" data-bind="attr: { accesskey: Id }" accesskey="7"> </td>
java code
public void portfolioRenewalSearch(String portfolioId) throws Exception { try { driver.findElement(By.xpath("//input[@accesskey= portfolioId]")) .click(); } catch (AssertionError Ae) { Ae.printStackTrace(); } }
but the above code show the Exception "selenium.NoSuchElementException"
-
Prashanth Sams almost 10 yearsdo u want the value 9 to be passed for the attribute, "accesskey" at runtime?
-
Prabu almost 10 yearsyes , check with my java code
-
-
Mathias Müller almost 10 years@Prabu Please accept this answer, if it solved your problem.