XPath not recognised in page object model in WebDriver



  • 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;
    


  • 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()
    }
    


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2