How do I convert Selenium web element to string?



  • To find my element, I used:

    String text = driver.findelement(By.xpath("xyz"));
    

    But it throws an error of type casting. I tried to use the code below to cast the element to a string:

    Driver.gettext(text);
    

    This gave me an error that the cast would not work.

    How do I get convert the web element to a string?



  • Use:

    String text = driver.findElement(By.xpath("xyz")).getText();
    


Suggested Topics

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