Reputation: 214
Click on the element for the below HTML code is not working.
a class="add" href="/travelPlan_revamp/addTravel.htm?travel_type=D">Add</a>
I'm using the next Xpath: html/body/div[1]/div[2]/div/a
But No Such Element Found
exception is displayed.
Upvotes: 1
Views: 2419
Reputation: 214
Sorry guys the the thing is it was in Iframe. Now i have found the solution by switching to the iframe and then clicking an event.
driver.switchTo().frame("rightMenu"); driver.findElement(By.xpath("html/body/div[1]/div[2]/div/a")).click();
Upvotes: 1
Reputation:
//a[@class='add' and text()='Add']
Try that one.
Through which method are you looking for the element?
@FindBy (how = How.XPATH)
or
driver.findElement(By.xpath());
Sometimes the @FindBy notation doesn't like working with Xpaths properly.
Upvotes: 0
Reputation: 23
An absolute xpath always starts with a forward slash '/'. I think you have used an absolute xpath and either you have missed'/' or you quoted it wrong here. Please verify it. Normally absolute xpath will look like /html/body/form/div[3]/div[2]/div[1]/div[2]/input
Upvotes: 1
Reputation: 896
First make sure the web element is not inside iframe. If yes, Then you need to switch to iframe first and then try clicking on element.
Also, try below xpath, in case you have captured wrong xpath:-
//a[@class='add' and .='Add']
Upvotes: 1
Reputation: 679
Hard to tell if your XPATH expression is right without the HTML. Your XPATH expression tell:
So checks there is a "a" element that check the Xpath expression.
Upvotes: 0