你成功安装watir了吗?
安装成功的话,require这句就不会出错了。
$ gem install watir
Fetching watir-7.1.0.gem
Fetching websocket-1.2.9.gem
Fetching rexml-3.2.5.gem
Fetching selenium-webdriver-4.2.1.gem
Fetching regexp_parser-2.5.0.gem
Fetching childprocess-4.1.0.gem
WARNING: You don't have /home/winn/bin in your PATH,
gem executables will not run.
Successfully installed childprocess-4.1.0
Successfully installed rexml-3.2.5
Successfully installed websocket-1.2.9
ERROR: Error installing watir:
The last version of selenium-webdriver (~> 4.0) to support your Ruby & RubyGems was 4.1.0. Try installing it with `gem install selenium-webdriver -v 4.1.0` and then running the current command again
selenium-webdriver requires Ruby version >= 2.7. The current ruby version is 2.6.4.104.
$ gem install selenium-webdriver -v 4.1.0
Fetching selenium-webdriver-4.1.0.gem
WARNING: You don't have /home/winn/bin in your PATH,
gem executables will not run.
Successfully installed selenium-webdriver-4.1.0
Parsing documentation for selenium-webdriver-4.1.0
Installing ri documentation for selenium-webdriver-4.1.0
Done installing documentation for selenium-webdriver after 9 seconds
1 gem installed
$ gem install watir
WARNING: You don't have /home/winn/bin in your PATH,
gem executables will not run.
Successfully installed regexp_parser-2.5.0
Successfully installed watir-7.1.0
Parsing documentation for regexp_parser-2.5.0
Installing ri documentation for regexp_parser-2.5.0
Parsing documentation for watir-7.1.0
Installing ri documentation for watir-7.1.0
Done installing documentation for regexp_parser, watir after 11 seconds
2 gems installed
$ irb
irb(main):001:0> require 'watir'
=> true
irb(main):002:0>
安装成功的话,require这句就不会出错了。
$ gem install watir
Fetching watir-7.1.0.gem
Fetching websocket-1.2.9.gem
Fetching rexml-3.2.5.gem
Fetching selenium-webdriver-4.2.1.gem
Fetching regexp_parser-2.5.0.gem
Fetching childprocess-4.1.0.gem
WARNING: You don't have /home/winn/bin in your PATH,
gem executables will not run.
Successfully installed childprocess-4.1.0
Successfully installed rexml-3.2.5
Successfully installed websocket-1.2.9
ERROR: Error installing watir:
The last version of selenium-webdriver (~> 4.0) to support your Ruby & RubyGems was 4.1.0. Try installing it with `gem install selenium-webdriver -v 4.1.0` and then running the current command again
selenium-webdriver requires Ruby version >= 2.7. The current ruby version is 2.6.4.104.
$ gem install selenium-webdriver -v 4.1.0
Fetching selenium-webdriver-4.1.0.gem
WARNING: You don't have /home/winn/bin in your PATH,
gem executables will not run.
Successfully installed selenium-webdriver-4.1.0
Parsing documentation for selenium-webdriver-4.1.0
Installing ri documentation for selenium-webdriver-4.1.0
Done installing documentation for selenium-webdriver after 9 seconds
1 gem installed
$ gem install watir
WARNING: You don't have /home/winn/bin in your PATH,
gem executables will not run.
Successfully installed regexp_parser-2.5.0
Successfully installed watir-7.1.0
Parsing documentation for regexp_parser-2.5.0
Installing ri documentation for regexp_parser-2.5.0
Parsing documentation for watir-7.1.0
Installing ri documentation for watir-7.1.0
Done installing documentation for regexp_parser, watir after 11 seconds
2 gems installed
$ irb
irb(main):001:0> require 'watir'
=> true
irb(main):002:0>