watir a string value is depriciated Ruby

289 Views Asked by At

Warn Watir [Depreciation] using the :class locator to locate multiple classes with a string value is deprecated. Use array instead

i get this error while running this line

browser.button(:class => '_t38eb _ov9ai').click

which i think is one class not multiple classes i tried this as mention in the warring

browser.button(:class => ['_t38eb','_ov9ai']).click

but the page freezes then terminate the web i'm trying to scarab is Instagram here trying to log in the page after filling the username and password field

and if i write this the chromedriver terminates

browser.button(:class == '_t38eb _ov9ai').click
2

There are 2 best solutions below

0
On BEST ANSWER

There is a difference between Chrome driver and Firefox Driver while you automate, Your browser is closing because chrome driver closes the browser once after the execution of your code but Firefox driver doesn't closes the browser. If you want to keep your chrome browser open, then use this code

require 'watir'
caps = Selenium::WebDriver::Remote::Capabilities.chrome(chrome_options: {detach: true})
b = Watir::Browser.new :chrome, desired_capabilities: caps

The given below code doesn't work

browser.button(:class == '_t38eb _ov9ai').click

That's because button() method need Hash Object not the object of TrueClass or FalseClass which you are passing while you write :class == '_t38eb _ov9ai'

If you want to pass an array, you may better use #split:

browser.button(:class => '_t38eb _ov9ai'.split).click
0
On

FYI: Watir is open source.

This line is the source of the deprecation warning.

The reason for this deprecation is to build the more idiomatic xpath with contains(this) and contains(that).

I am not sure why it's freezing, but I am positive it’s completely safe to ignore the warning.