-1

Part of it look like this:

<input type="hidden" id="recaptcha-token" value="Need This Value">

I'm running Selenium like this:

driver.findElement(By.xpath("[@id=\"recaptcha-token\"]"));

How I can get "Need This Value" from running this code ?

Mat
  • 1,440
  • 1
  • 18
  • 38
  • 1
    Possible duplicate of [Selenium WebDriver findElement(By.xpath()) not working for me](https://stackoverflow.com/questions/16952514/selenium-webdriver-findelementby-xpath-not-working-for-me) – Mat Feb 25 '19 at 21:28
  • 1
    Possible duplicate of [Using Selenium Web Driver to retrieve value of a HTML input](https://stackoverflow.com/questions/7852287/using-selenium-web-driver-to-retrieve-value-of-a-html-input) – JeffC Feb 25 '19 at 22:48

1 Answers1

0

For your specific case, you can first get the element like so:

driver.findElement(By.xpath("//*[@id='recaptcha-token']")); // Any element with that id

driver.findElement(By.xpath("//input[@id='recaptcha-token']")); // More specific to your tag

And then you get the attribute you want using getAttribute(String attrName).

A one-liner would then be:

driver.findElement(By.xpath("//input[@id='recaptcha-token']")).getAttribute("value");

If you only want to look for an element with that id, you could simplify that call by using By.id() instead of By.xpath():

driver.findElement(By.id("recaptcha-token"));
Mat
  • 1,440
  • 1
  • 18
  • 38
  • See [this answer](https://stackoverflow.com/a/16955672/6923568) specifically for the `By.xpath` portion of the answer, – Mat Feb 25 '19 at 21:53