Hey Navi, I'm sorry there is so much confusion around the waits. If there is something that would make this article (http://watir.com/guides/waiting/) more clear, please let me know so I can make it better. Maybe I spend too much time focusing on history and implementation details that don't matter to you?
Best practice before Watir 6: Scenario one, click element that eventually displays: my_element.when_present.click Scenario two, get info from element that eventually displays: my_element.when_present.get_attribute('class') Secnario three, wait for one element then act on another: my_element1.wait_until_present my_element2.click For the first scenario, since your test shouldn't attempt to click an element that isn't present, Watir 6 made the waiting automatic. This will now do the exact same thing: my_element.click Scenario 2: Watir waits for the element to exist, but not for it to be displayed. So if it needs to be displayed first (usually some kind of dynamic activity on the page): element.wait_until(&:present?).attribute_value('class') Scenario 3: element_one.wait_until(&:present?) element_two.click We are encouraging everyone to move to the to_proc notation `&:` with the wait methods. This drastically simplifies the code we have to maintain relative to the benefit to our users. We do still have `#wait_until_present` and `#wait_while_present` methods to handle some special use cases, but these may go away as well. Does this clarify things more? On Tuesday, September 11, 2018 at 9:49:37 PM UTC-7, NaviHan wrote: > > > Hi Titus > > You said "when_present" and 'wait_until(&:present?)" does the same thing, > which is Waits for element to be present, the former is deprecated and > latter is recommended. > > Why is that if bot does the same thing > > Im trying to understand if "wait_until(&:present?)" is in any ways > different from "when_present" eventhough its deprecated. > > > Justin also mentioned on version 6.0 of Watir you made changes to > automatically wait for elements before taking actions which let us do away > ith "when_present". So I still do not understand why we should ever use > wait_until(&:present?) at all. > > Sorry if I sound stupid, becasue there is so much cinfusion around waits > :-( > > Cheers > Navi > > On Tuesday, 11 September 2018 14:52:33 UTC+10, NaviHan wrote: >> >> This is something that keeps me a bit sceptic when I write and read the >> automation code in my project. >> This used PageObjects. >> >> I have seen extensive use of element referces, for example >> >> button(:add_to_bag, :css => '#add-to-cart') >> add_to_bag.element.when_present.click >> >> >> >> instead of >> >> add_to_bag >> >> which directly clicks the element >> >> I have also seen extensive use of referencing elements using >> <element>.when_present, <element>.wait_until_present etc >> >> Im confused where we should draw the line when deciding to reference the >> element and actually using it(as in directly calling "add_o_bag" in the >> above example to click the element. >> >> Any thoughts? >> >> >> -- -- Before posting, please read https://github.com/watir/watir_meta/wiki/Guidelines-for-Posting-to-Watir-General-Google-Group. In short: search before you ask, be nice. watir-general@googlegroups.com http://groups.google.com/group/watir-general watir-general+unsubscr...@googlegroups.com --- You received this message because you are subscribed to the Google Groups "Watir General" group. To unsubscribe from this group and stop receiving emails from it, send an email to watir-general+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.