Anik_Datta
Anik_Datta

Reputation: 1

Difference in xpath in selenium webdriver?

WebElement we4=driver.findElement(By.xpath("/html/body/div/table/tbody/tr[2]/td[2]/div/div/div/div[4]/ul/li[3]/a"));

WebElement we3=driver.findElement(By.xpath("//*[@id='nav_cat_3']"));

While copying the xpath by firebug, both the xpath are coming alternatively. What is the differenence between them though both are working?

Upvotes: 0

Views: 203

Answers (1)

Ittiel
Ittiel

Reputation: 1224

First one goes over the DOM, element by element. If the order of the displayed element changes, this will stop working

Second example goes to the element that has an id called nav_cat_3. ID is suppose to be unique on the web page and is prefered

Upvotes: 1

Related Questions