Akalanka
Akalanka

Reputation: 65

Xpath OR condition for two different elements in the DOM

I have a selenium jbehave project with maven build.in step class i want to add an OR condition for two types of DOM elements.for same element i know how to do it.how can i do it for different elements?

@Then("I click $Search Button")
public void clickSearchGoogleButton(String search) {
    driver.findElement(By.xpath("//input[@aria-label='"+search+"']")).click();
}

in the above code what i want to do is i have a button element with "aria-label" so i want to add it to the same xpath condition with an or condition.i have tried below but it gives an error.

@Then("I click $Search Button")
public void clickSearchGoogleButton(String search) {
    driver.findElement(By.xpath("//input[@aria-label='"+search+"'] or //button[@aria-label='"+search+"']")).click();
}

any help would be great.

Upvotes: 0

Views: 127

Answers (1)

Deb
Deb

Reputation: 2972

You can use | instead of or

By.xpath("//input[@aria-label='"+search+"'] | //button[@aria-label='"+search+"']")

Upvotes: 2

Related Questions