使用Selenium Web Driver检索HTML输入的值 [英] Using Selenium Web Driver to retrieve value of a HTML input

查看:90
本文介绍了使用Selenium Web Driver检索HTML输入的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网络应用的HTML中,有以下代码

In the HTML of a webapp there is the following code

<input type="text" name="prettyTime" id="prettyTime" class="ui-state-disabled prettyTime"  readonly="readonly">

页面上实际显示的是显示时间的字符串。

What is actually shown on the page is a string displaying the time.

在Selenium Web Driver中,我有一个 WebElement 对象,指的是< input> 使用

In Selenium Web Driver, I have a WebElement object referring to the <input> using

WebElement timeStamp = waitForElement(By.id("prettyTime"));

我想获得 WebElement ,或者换句话说,页面上打印的内容。我尝试了所有 WebElement getters,并没有检索到用户看到的实际值。有帮助吗?谢谢。

I want to get the value of the WebElement, or, in other words, what is printed on the page. I tried all the WebElement getters and nothing has been retrieving the actual value that the user sees. Any help? Thanks.

推荐答案

这有点hacky,但它确实有效。

This is kind of hacky, but it works.

我使用了 JavascriptExecutor 并在HTML中添加了 div ,并更改了 div $('#prettyTime')。val()然后我用Selenium检索 div 并抓住它的价值。在测试了值的正确性后,我删除了刚刚创建的div。

I used JavascriptExecutor and added a div to the HTML, and changed the text in the div to $('#prettyTime').val() I then used Selenium to retrieve the div and grab its value. After testing the correctness of the value, I removed the div that was just created.

这篇关于使用Selenium Web Driver检索HTML输入的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆