4
votes

Why are all the elements located false?

browser.divs.collect { |div| p div } #=>
#<Watir::Div:0x6b00922dc26e0b0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fc49d26028c70a780 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x5845c71f58d40810 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fe5d8004222b06fe0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fdabeedaf54ef9220 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fa6b0f134aa2552b0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x7b398ed8727c1a10 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x6960c079dfc53e70 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x3066bfe4aca244c8 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x78183373aaf5bb98 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fb97ea89cfbe50c28 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..f8516f53906926400 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x15c0a77a1c2b2490 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fb20a77589d504be8 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x413b24c40adbaeb8 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x5082c3c6fcab0050 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fb5b91eb5d97b6720 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fef34927ce86acbb0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fe355d6cf2c122e80 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fc298449a2ccbef10 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x60c8a26d48ce2e0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x7bbd012d36dc7770 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x5a131e661527aa40 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fce74fbbff21d6ad0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x4ce44bfa8b6695a0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..f9a7a3d80975c5230 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x4e515aa604c78900 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x2b9ca16a9c1d4990 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x5af1408ac7077160 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x75f49c45c2e787b8 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x584694dea3dd4448 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..f93940ef962bb1b18 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x348584082e90dba8 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x3144b8ecc252c378 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x4a8cc4f6f0b8308 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..f8bd836584d3be6d8 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x4f0e9f29854b4b68 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..feb920ae0d472ae38 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fb16c0c9e44203d0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fe145f926e7f266a0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x813352af82b2730 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x5cad2d48230d2e00 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..f99c4f7c68d978e90 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fca8a6c43dca7e260 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fe09510792dfca2f0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fad6b90b6dc5eadc0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x295d6bdcf047f018 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x6ff137efc4bcb0a8 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fb83092b42841478 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x1f38168bf8c7dfd8 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fad6f4b1717935338 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0xe068cbe2682a7c8 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x39333d92a84cbfa0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x8e29f34f5227c30 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x1e716dfa392dd300 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0xf4d3daf64629390 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..f8c99737270ec9b60 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..feedea131b3a25bf0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x31d45beea32dbec0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x46a230b8f3dd0350 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x73779048d96d6620 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x47508d81e577c6b0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fa597b94c5c7f3d80 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..f854f1b2208e8e10 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x6259997c483ee5e0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fb6bb84691f17a270 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x1a2d6c8537f1940 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x45b47e7cff0f6dd0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x2cae546b88bec0a0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..f8f868f3553178130 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x2c67b97a04f98800 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fc0192df0120f4890 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..f967334b6fd8d0c60 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fadd345b274c2ccf0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x155ef60e3a24f7c0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x377ad1b63ffdb450 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x19bac99ef08deb20 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..fa4cd04862bbd7fb0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x27a21a5d7aa4d280 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x..f6fea500051d9310 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x3bf03ec6590df6e0 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x69fda612b35d5b70 located=false selector={:element=>(webdriver element)}>
#<Watir::Div:0x180fa81f39a4be40 located=false selector={:element=>(webdriver element)}>

I'm saying because there are many times non-found elements, give errors. Take Etsy for example:

b = Watir::Browser.new :chrome
b.goto "https://www.etsy.com/ca/signin?from_page=http%3A%2F%2Fwww.etsy.com%2F&ref=so_sign"
b.text_field(:name, "username").set "Robert" #=> error
b.text_field(:name, "password").set "Robert" #=> error
2
Are you asking from a curiosity of how watir-webdriver is implemented or is there a functional issue?Justin Ko
Thanks for pointing that out. It's a functional issue. Updated to reflect.Mr. Demetrius Michael

2 Answers

5
votes

My interpretation of the located=false is that Watir itself has not tried to locate the elements. When Watir creates an element collection, it fetches all the elements returned by selenium and maps them into new Watir element objects. These new Watir element objects have not been "located" in Watir's view. The located will be true if you try interact with the element.

However, I think that is just a Watir implementation detail. It does not appear to be the cause of your problem.

The problem is that there are 3 text fields on the page with the name "username" (and similar for the password).

browser.text_fields(:name, 'username').each{ |e| puts e.html }
#=> <input autocorrect="off" autocapitalize="off" class="text" name="username" id="username" maxlength="20" type="text">
#=> <input autocorrect="off" autocapitalize="off" class="text" name="username" id="username-existing" tabindex="1" type="text">
#=> <input id="username-existing" autocorrect="off" autocapitalize="off" name="username" value="" class="text " type="text">

It looks like you actually want to be interacting with the last one (rather than the first one which Watir will select by default). I believe this is mostly easily done by scoping your search to elements within the login form:

form = b.form(:id => 'loginForm')
form.text_field(:id, "username-existing").set "Robert"
form.text_field(:id, "password-existing").set "Robert"
0
votes

"element exists, but located == false", normally it means "there are so many such elements, so cannot know which one to locate. So you need check if there are serval windows or serval forms, or serval other containers.