'How to open a Chrome window with Watir

I can't manage to make Watir run properly.

I followed all the instructions step by step, installing Watir and the Chrome drivers, and checked that the drivers and Chrome are the same version, v98.0.

Still, with this simple code:

require 'watir'

b = Watir::Browser.new

I can see the Chrome window open, but after less than a second it closes itself automatically.

What can be the problem?



Solution 1:[1]

Chrome window automatically closes. That was expected. Write the code as shown below

require 'watir'

b=Watir::Browser.new

b.goto 'www.google.com'

b.text_field(name: 'q').set 'Hi how are you'

sleep 20

Now you can see after the execution browser remains alive for 20 seconds.

Firefox runs fine for me. Don't load any profile, write as given below

require 'watir'

b=Watir::Browser.new :firefox

b.goto 'www.google.com'

b.text_field(name: 'q').set 'Hi how are you'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rajagopalan