![](/img/trans.png)
[英]How to get the Email/Text entered into a field when there is no “value” attribute or text in the code snippet for Java Selenium
[英]How to get entered text from a textbox having no value attribute in selenium
我的元素看起来像这样:
<input name="ctl00$PlaceHolderPopUp$ReviewName"
type="text" maxlength="255" id="PlaceHolderPopUp_ReviewName"
class="giInput_two inputHeight_two"
style="height:20px;width:100%;">
检索代码:
String value=driver.findElement(By.xpath("//*@id='PlaceHolderPopUp_ReviewName']")).getText().trim();
我想在其中输入一些文本并在保存之前检索文本。 我使用了getText()
方法,但是它没有检索任何文本。
您可以将要输入的字符串输入变量,并在脚本中使用它。 例如:
String Text ="Name"
Driver.findElement(By.xpath("//*@id='PlaceHolderPopUp_ReviewName']")).sendkeys(Text);
因此,您可以在任何需要的地方使用Text变量,而不用从文本框中读取它。
如果您真的想阅读,可以尝试使用getAttribute("Value")
而不是getText()
<input _ngcontent-c16="" class="form-control input-sm ng-touched ng-dirty ng-valid" formcontrolname="usrPwd" id="usrPwd" maxlength="15" name="usrPwd" type="password" placeholder="Password">
如果没有“值”属性,那么如何从“密码”文本框中检索文本
下面提供了我的代码以供参考。
WebElement Password = driver.findElement(By.id("usrPwd"));
Password.sendKeys("Future1234");
String Text = driver.findElement(By.id("usrPwd")).getAttribute("Value");
System.out.println(Text);
如果目标元素是input
元素,则应尝试以下操作:
WebElement el=driver.findElement(By.xpath("//*@id='PlaceHolderPopUp_ReviewName']"));
String value = el.getAttribute("value");
注意 :- input
元素始终在其属性属性value
包含输入的文本。 是否存在它们的属性value
并不重要。 希望对您有帮助... :)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.