简体   繁体   English

Selenium WebDriver,从DOM获取,从空值获取

[英]Selenium WebDriver, get from DOM, from empty value

I have field, that after few minutes will be filled. 我有一个领域,几分钟后将被填补。 So far so good. 到现在为止还挺好。 But when is filled, in inspect elements it's look like: 但是当填充后,在检查元素中看起来像:

<div class="column1 last">
              <input type="text" name="usedFile" size="100" value="" readonly="readonly" style="width:99%" class="disabled">
            </div>

So, in front-page, the text is visible: "Some text", but when i click inspect element, it's show this above. 因此,在首页上,该文本是可见的:“某些文本”,但是当我单击inspect元素时,它在上方显示。 So how, I can get the text from filed? 那么,如何从归档中获取文本呢? It's DOM this? 这是DOM吗?

String text = driver.findElement(By.name("usedFile")).getText();

This is a textbox so you cannot use getText() in it. 这是一个文本框,因此您不能在其中使用getText()。 To get data out of it , you need following code 要从中获取数据,您需要以下代码

String text = driver.findElement(By.name("usedFile")).getAttribute("value");

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM