In that example, you should just #add_to_bag.

I'm guessing that you are working with a code base that is older than Watir 
6.0. Before v6.0, add_to_bag_element.when_present.click was required for 
elements that were not immediately present on page load (ie you needed to 
wait for them to appear). In Watir 6.0, Titus made changes to automatically 
wait for elements before taking actions. As a result, pre-6.0 
add_to_bag_element.when_present.click would be equivalent to v6.0 
add_to_bag_element.click. add_to_bag_element.click is equivalent to the 
accessor created add_to_bag.

In general, I would say:
- You do not need the waits when taking actions (eg click, inputting, etc) 
on an element.
- Use the page object accessor's methods if available (ie don't duplicate 
the framework)

Justin


On Tuesday, September 11, 2018 at 12:52:33 AM UTC-4, 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.

Reply via email to