Sunny
Sunny

Reputation: 105

How to change the flash color?

I want to change the flash color when using element.flash method. By default its yellow. I was able to increase the number of flash times and delay time in elements.rb file. But i dont know how to change the highlight color. Any idea on this?

Using different colors to highlight will be helpful if browser elements have yellow background.

Upvotes: 2

Views: 424

Answers (1)

Justin Ko
Justin Ko

Reputation: 46836

Solution

The flashing is based on the element's container's activeObjectHighLightColor. This is set by doing:

element.container.activeObjectHighLightColor = "colour"

Where colour is a valid web-friendly color (as per the container.rb file).

Example - Flash For Individual Element

As an example, here is changing the flash colour for the text field on the Google search:

#Use google search text field as a test page
ie = Watir::Browser.new
ie.goto 'www.google.ca'
e = ie.text_field(:name => 'q')

#Set the flash colour
e.container.activeObjectHighLightColor = "green"

#Flash the object, which should now be green
e.flash

Note:

  • This will only work with Watir-classic. Watir-webdriver does the flashing differently.
  • I only tested this in the latest version of watir-classic, but the code for 2.0.4 appears to be the same.

Example - Default Flash Colour

To change the default flash colour for everything, you need to set the activeObjectHighLightColor for the browser.

If you want to change it for the current browser, do:

ie = Watir::Browser.new
ie.activeObjectHighLightColor = "green"

ie.goto 'www.google.ca'
e = ie.text_field(:name => 'q')
e.flash
#=> Will flash green

If you want to change it permanently (ie so you do not have to set it each time), you can change the colour in the ie-class.rb file:

HIGHLIGHT_COLOR = 'yellow'

Upvotes: 2

Related Questions