官网(下载):https://www.selenium.dev/downloads/

语法:https://www.selenium.dev/documentation/webdriver/getting_started/first_script/

Selenium Grid 允许在远程机器上执行 WebDriver 脚本 通过将客户端发送的命令路由到远程浏览器实例。

网格旨在:

  • 提供一种在多台机器上并行运行测试的简单方法
  • 允许在不同的浏览器版本上进行测试
  • 启用跨平台测试

选择版本后,下载,安装:

chmod +x selenium-server-4.4.0.jar
./selenium-server-4.4.0.jar

脚本:

require 'selenium-webdriver' driver = Selenium::WebDriver.for :chrome driver.get 'https://selenium.dev' driver.quit

然后运行的时候出现了:Unable to find chromedriver. Please download the server from (Selenium::WebDriver::Error::WebDriverError

https://stackoverflow.com/questions/19862276/unable-to-find-the-chromedriver-executable

解决:

sudo apt-get install chromium-chromedriver

再次运行命令,执行脚本:

下载:https://github.com/mozilla/geckodriver/releases

其他版本:https://www.selenium.dev/documentation/webdriver/getting_started/install_drivers/

查看版本:(多种方式查看:https://blog.csdn.net/weixin_34534456/article/details/116808628)

uname -m

解压:

tar -zxvf geckodriver-v0.31.0-linux64.tar.gz

使用方式:(大多数机器会自动更新浏览器,但驱动程序不会。  为确保您获得正确的浏览器驱动程序,有许多第三方库可以为您提供帮助。

第一种:

gem 'webdrivers', '~> 5.0'

第二种:

require 'webdrivers'

第三种:

driver = Selenium::WebDriver.for :chrome

使用:

./geckodriver

安装 Selenium 库
 为您最喜欢的编程语言设置 Selenium 库。

 首先,您需要为自动化项目安装硒绑定。  库的安装过程取决于您选择使用的语言。  确保检查硒下载页面以确保您使用的是最新版本。

gem install selenium-webdriver

或者添加

gem 'selenium-webdriver', '~> 4.4'

此时,运行脚本的时候,需要使用

./geckodriver
1661754159322    geckodriver    INFO    Listening on 127.0.0.1:4444

在另一个窗口打开

ruby xxx.rb

这样就可以打开浏览页面。