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 ?
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 ?
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"));