简体   繁体   English

如何使用 Watir 打开 Chrome window

[英]How to open a Chrome window with Watir

I can't manage to make Watir run properly.我无法让 Watir 正常运行。

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.我按照所有说明一步步安装了 Watir 和 Chrome 驱动程序,并检查了驱动程序和 Chrome 的版本是否相同,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.我可以看到 Chrome window 打开,但不到一秒后它自动关闭。

What can be the problem?可能是什么问题?

Chrome window automatically closes. Chrome window 自动关闭。 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.现在您可以看到执行后浏览器保持活动状态 20 秒。

Firefox runs fine for me. Firefox 对我来说运行良好。 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'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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