Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

xpath not recognised in page object model in webdriver.

@FindBy(xpath = "//td[contains (text(),'xxx')]")
public WebElement topMenu;

topMenu.click();

Error: Unable to locate element: {"method":"xpath","selector":"//td[contains (text(),'xxx')]"}

I'm using page object model in WebDriver. Any suggestions?

So this is my actual code of my program

public WebElement userName;
public WebElement password;
public WebElement id;
@FindBy(xpath = "//td[contains (text(),'Procurement')]")
public WebElement topMenu;
share|improve this question

closed as unclear what you're asking by dzieciou, Kate Paulk, Niels van Reijmersdal, corsiKa Apr 2 at 15:34

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

    
I expect your HTML to contain an excerpt <td>Procurement</td>. Is it there? –  dzieciou Mar 20 at 10:43
    
@dzieciou Now i have edited the error –  Emmanuel Angelo.R Mar 20 at 11:23
    
Can you then provide also your HTML document, or at least its relevant part? –  dzieciou Mar 20 at 12:36
    
i dont have any html documents it is displayed in my eclipse console –  Emmanuel Angelo.R Mar 20 at 12:40
    
Well, I guess it is evaluated over some Web page (HTML), when you run your test with your PageObject, right? –  dzieciou Mar 20 at 13:12

2 Answers 2

up vote 1 down vote accepted

There are two parts to this. The first is that you need to be sure that your xPath is correct. One way to validate that is to use a tool like Firefinder (a firefox extension for firebug). Navigate to your page and be sure the element you need is present and then hit f12 and go to the FireFinder section. Enter in the xpath you are using and see if it can be found.

Assuming your xpath is correct then you might want to investigate using an explicit wait if from some reason you are waiting on the page element to load.

Example:

    WebDriverWait wait = new WebDriverWait(_driver, 10);
    wait.until(ExpectedConditions.visibilityOf(topMenu));
    topMenu.click();

I would suspect though this is failing because your xPath is not quite right.

share|improve this answer

Can you find it if you use the .Text and then clicking it if it matches?

String Expectedtext = "Procurement"
String ProcurementButtonText = driver.FindElement(By.XPath("//td")).Text;


if (ProcurementButtonText == Expectedtext)
{
   driver.FindElement(By.XPath("//td")).click()
}
share|improve this answer
    
sure user i wil make your suggestion. –  Emmanuel Angelo.R Mar 28 at 12:48

Not the answer you're looking for? Browse other questions tagged or ask your own question.