简体   繁体   中英

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?

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'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM