aswathy
aswathy

Reputation: 831

How to use multiple locators to find an element in selenium webdriver

How can I locate an element in a page with selenium webdriver by using multiple locators at the same time . I am having 2 elements with same id but different values. So in order to access them I need to use a combination of both id and value. What is the syntax. I'm using java. Also I'm automating an application that works only in IE. Since I'm unable to access xpath, I'm not using it.

element=driver.findElement(By.id("id").cssSelector("input[@value='value1']"));

Upvotes: 4

Views: 23381

Answers (2)

Guy
Guy

Reputation: 50809

cssSelector can be used to locate elements by id, class or any other attribute, or combination of those. For example, you can locate the element using

element = driver.findElement(By.cssSelector("#id[value='value1']"));

Upvotes: -1

Gaurang Shah
Gaurang Shah

Reputation: 12900

Xpath allows you to use and and or to evalute multiple attributes. so you can form an xpath using this

//input[@id='id' and @value='value1' or @value='value2']

For example on google home page, there are two buttons, Google Search and I'm Feeling Lucky. Both has same type submit to find these buttons I can form an xpath similar to this

//input[@type='submit' and @value='Google Search' or @value="I'm Feeling Lucky"]

Upvotes: 3

Related Questions