我不知道如何让 jQuery fadeIn 工作,但我使用了切换。我希望这没问题。
<html>
<head>
<style>
#input {
font-weight: bold;
font-size: 16px;
}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<input type='checkbox' id='check'>Toggle</button>
<input id = 'input' placeholder = 'name'></input>
<script>
$( "#check" ).click(function() {
$( "#input" ).toggle( "slow" );
});
</script>
</body>
</html>
您需要使用 rubysleep (time)
等待 jQuery/AJAX 元素完成。这是一个解释Watir 等待方法的链接。
我使用 Rspec 和 Watir-Webdriver 来自动化浏览器。这是一个快速的片段,这可能更清晰,但它应该为您尝试完成的工作提供一些方向。
require 'rspec'
require 'watir-webdriver'
describe 'fade' do
before(:all) do
@browser = Watir::Browser.new :chrome
@browser.goto('file:///C:/Users/bashir.osman/Desktop/test.html')
end
it 'checks fade' do
puts "so...#{@browser.input(:id, 'check').exists?}"
@browser.input(:id, 'check').click
sleep 1
exists1 = @browser.input(:id, 'input').visible?
if exists1 == false
puts 'Currently input is not visible'
puts 'Will click input again'
@browser.input(:id, 'check').click
sleep 1
exists2 = @browser.input(:id, 'input').visible?
exists2.should == true
end
end
end
这就是测试的作用:
- 点击复选框
- 检查是否
#input
可见。这应该返回 false。
- 再次点击复选框
- 检查 `#input 是否可见。这应该返回 true
我不会使用.exists?
,因为它总是返回 true,因为元素存在于 DOM 中。present?
如果元素存在并且在页面上可见,则返回 true。visible?
根据元素是否可见返回真/假。