简体   繁体   中英

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

I have the following 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. I have also tried using b.text_field(:name => 'email').exists? , but it returns false as well.

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 .

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:

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

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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