Prabu
Prabu

Reputation: 3728

xpath identification Dynamic value passing

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"

Upvotes: 1

Views: 18043

Answers (1)

Prashanth Sams
Prashanth Sams

Reputation: 21129

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();
    }
}

Upvotes: 5

Related Questions