Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getAttribute("value") returning null value, why?

My code is

String OTP = driver.findElement(By.xpath("//span[@id='otp']")).getAttribute("value");
System.out.println(OTP);
like image 792
Sujit Avatar asked Oct 30 '22 19:10

Sujit


1 Answers

Assuming you are trying to get the text in the span. getAttribute("value") only works for textbox, textarea. For span div and others use getText()

driver.findElement(By.xpath("//span[@id='otp']")).getText();
like image 167
Grasshopper Avatar answered Jan 02 '23 19:01

Grasshopper