问题描述
我需要自动化一个场景,其中文本输入字段在那里,文本 -显示在此处输入".
Hi I need to automate a sceanrio where a text input field is there, where a text - "type here" is displayed.
<input class="textbox" type="text" value="" placeholder="type here" name="q">
我需要验证1) 显示文字 - 在此处输入"2)当焦点移到这个文本框时,文本输入框不显示——在此处输入"
I need to verify1) Text is displayed - "type here"2) When focus is moved to this text field, the text input field does not display - "type here"
推荐答案
您可以通过一个简单的方式测试浏览器是否支持 元素的
placeholder
属性JavaScript.这是一个间接测试,但据我所知,您无法通过 Selenium 测试占位符文本.但它应该是绝对足够的:
You can test whether the browser supports the placeholder
attribute for <input>
elements via a simple JavaScript. This is an indirect test, but as far as I know, you can't test for the placeholder text via Selenium. But it should be absolutely sufficient:
function supportsInputPlaceholder() {
var input = document.createElement('input');
return 'placeholder' in input;
}
(取自 http://diveinto.html5doctor.com/detect.html#input-占位符)
因此:
// only if your driver supports JS
JavascriptExecutor js = (JavascriptExecutor)driver;
String placeholderTest = "return 'placeholder' in document.createElement('input')";
assertTrue(js.executeScript(placeholderTest));
这篇关于我应该如何使用 webdriver 处理 html 占位符属性场景自动化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!