RE: Xpath not working
the following code is not working, xpath is taken from Firebug
locater = By.xpath(“/html/body/font/div/div[2]/div/div/div/div[2]/div[3]/div[1]/div/div/a[1]”);
driver.findElement(locater).click();
What is the reason ? Is Xpath reliable ?
we should not use absolute Xpath that will leads to error in dynamic pages , i recommend u should use Random xpath along with
1. ancestor
2. decedent
3.parent
4.child
5.following
6.following-sibling and preceding -siblings
use these concept and try to construct you own xpath
locater = By.xpath(“/html/body/font/div/div[2]/div/div/div/div[2]/div[3]/div[1]/div/div/a[1]”);
driver.findElement(locater).click();
solution :
use this Xpath : //a[Contains(text(), “you link text”)]
**** CSS is more effective and time saving in selenium automation over any browser -(*IE)
so please use CSS instead Xpath , in dynamic scenarios only you can use Xpath ( // a[Contains(text(), strVar)] where strVar= some dynamic values on page
Thanks,
Anbarasan J.
Selenium Automation – Cognizant tech solutions