简体   繁体   English

在Chrome中使用watir-webdriver-无法找到输入字段?

[英]Using watir-webdriver with chrome - can't locate input field?

I have the following HTML: 我有以下HTML:

<input type="email" class="form-control" name="email" placeholder="Email">

And I am trying to retrieve this element with the following code: 我正在尝试使用以下代码检索此元素:

b = Watir::Browser.new :chrome
b.goto('localhost:3000')
puts b.input(:name => "email").exists?

This returns false , but is most definitely true. 这将返回false ,但绝对是正确的。 I have also tried using b.text_field(:name => 'email').exists? 我也尝试过使用b.text_field(:name => 'email').exists? , but it returns false as well. ,但它也会返回false

The end goal is to change the text of the input, but I can't even locate the element right now. 最终目标是更改输入的文本,但我现在甚至无法找到该元素。 The page loads fine, and after loading it outputs false . 该页面加载正常,加载后输出false

The issue is your code is actually being executed before the element is finished loading. 问题是您的代码实际上是在元素加载完成之前执行的。 You need to chain a few methods (namely .when_present and .exists? to ensure your element is loaded before attempting to check it's existence: 您需要链接一些方法(即.when_present.exists?以确保在尝试检查元素是否存在之前已加载元素:

puts b.input(:name => "email").when_present.exists?

Good luck! 祝好运!

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

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