oz icon indicating copy to clipboard operation
oz copied to clipboard

Title Element cannot be used for ID or Wait Element

Open PanoramicPanda opened this issue 7 years ago • 11 comments

Due to the both way core_element determines the watir_element and the required arguments of an ID Element, the Title of the HTML page cannot be used.

Watir's call of browser.title just directly returns the title string, with no arguments required. Since ID Elements utilize parent.send(@element_type, @locator_hash) and the title needs no locator, we cannot use it.

Unsure if we'd ever really want to use it as a Wait Element, but can't be used there either due to the same effect.

PanoramicPanda avatar Dec 13 '18 17:12 PanoramicPanda

Making this possible would also require a re-work in how the ID element would determine presence, as the title just returns a string back instead of an element.

PanoramicPanda avatar Dec 13 '18 17:12 PanoramicPanda

If i'm remembering correctly, #.title is actually an attribute on the window (in chrome's case, this is a tab.) And Watir::Browser#instantiated.title will just return the title of the currently selected window. You can actually test this with irb

irb(main):044:0> @browser.windows.map{|it| it.title}
=> ["Hello World - Google Search", "Stack Overflow - Where Developers Learn, Share, & Build Careers"]

From an implementation standpoint, we could probably create a WindowElement in oz that overrides value to call watir_element.title where element_type: window

Castone22 avatar Dec 13 '18 19:12 Castone22

class WindowElement < CoreElement
  def self.element_type; :window end
  def value
    watir_element.title
  end
end

Something like that

Castone22 avatar Dec 13 '18 19:12 Castone22

While this does definitely help (and I had the same thing worked out in my head), the ID Element would still need changed a bit to handle it, as it takes a element type, value, and locator hash. We might be able to just have it be bogus and the element ultimately ignore it, but that feels... dirty.

PanoramicPanda avatar Dec 13 '18 20:12 PanoramicPanda

Technically speaking, window can take a selector.

window(title: /Google/)

Castone22 avatar Dec 13 '18 20:12 Castone22

this means we'd have to add title as a valid selector though.

Castone22 avatar Dec 13 '18 20:12 Castone22

but add_id_element(:window, /Google/, title: 'Google') would feel a bit redundant.

Where as add_id_element(:window, /Google/) doesn't.

PanoramicPanda avatar Dec 13 '18 20:12 PanoramicPanda

Caught me on my own argument with that one... that's a great point.

Castone22 avatar Dec 13 '18 20:12 Castone22

would we be okay defaulting the selector to {}?

Castone22 avatar Dec 13 '18 20:12 Castone22

🤔 Perhaps? @greenarrowdb I'd like your input on this issue at some point

PanoramicPanda avatar Dec 13 '18 20:12 PanoramicPanda

@greenarrowdb

Castone22 avatar Jul 12 '19 18:07 Castone22