简体   繁体   English

如何从Selenium Webdriver Java获取只读文本的文本

[英]How to do get text of read only text from Selenium webdriver java

Application has a text filed which displays dynamically changes, after getting value of the weight of a product,that is read only, I am not able to read the values from it. 应用程序具有一个text filed ,该文件显示了动态变化,在获取了产品重量的值(只读)之后,我无法从中读取值。 Here is the code: 这是代码:

WebElement input = driver.findElement(getLocator("Weight1Value"));
System.out.println(input.getAttribute("value"));

You can try JavascriptExecutor if the above is not working 如果以上方法无效,您可以尝试使用JavascriptExecutor

JavascriptExecutor jse = (JavascriptExecutor)driver;
String Text = (String) jse.executeScript("return arguments[0].value;",driver.findElement(getLocator("Weight1Value")));

@Arun, just made small change & it's working fine for me @Arun,只是做了一些小改变, 对我来说一切正常

JavascriptExecutor jse = (JavascriptExecutor)driver;
String Text = (String) jse.executeScript("return arguments[0].value;",driver.findElement(getLocator("Weight1Value")));
System.out.println(Text);
  • I had made mistake in getting the xpath as well. 我在获取xpath也犯了错误。

all fixed now, thanks guys 现在都固定了,谢谢

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Selenium WebDriver和Java从图像(验证码)中读取文本 - How to read the text from image (captcha) by using Selenium WebDriver with Java 如何通过与Java一起使用Selenium WebDriver从此HTML代码中获取文本 - How to get Text from this HTML code By using Selenium WebDriver with Java 如何使用Selenium WebDriver Java从标签内部获取文本? - How to get text from inside tag use selenium webdriver java? 如何使用Selenium Webdriver和Java从元素中获取文本? - How can I get text from element with Selenium webdriver and Java? 使用Java中的Selenium Webdriver获取文本 - Get Text with Selenium Webdriver in Java 如何仅从子元素中获取文本 - Webdriver - Java - How to get the text only from the child element - Webdriver - Java Selenium Webdriver-Java-从Gmail获取特定文本 - Selenium Webdriver - Java - Get a specific text from Gmail 是否可以使用Java使用Selenium WebDriver从验证码图像中获取文本? - Is it possible to get text from captcha image with Selenium WebDriver using Java? 如何使用Selenium WebDriver从隐藏元素中读取文本? - How to read text from hidden element with Selenium WebDriver? Java/Selenium WebDriver:如何获取用户输入并将其插入到文本字段中? - Java/Selenium WebDriver: How to get user input and insert it in to a text field?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM