Selenium Grid(一)环境搭建
Selenium Grid(二)控制远程电脑运行自动化
首先本地启动hub节点
java -jar selenium-server-standalone-3.141.59.jar -role hub
本地也可以启动node节点(多个node需要指定不端口号)
java -jar selenium-server-standalone-3.141.59.jar -role node -port 5556
java -jar selenium-server-standalone-3.141.59.jar -role node -port 5557
去远程电脑上启动,-hub后面指定hub主机IP
java -jar selenium-server-standalone-3.141.59.jar -role webdriver -port 5558 -hub http://192.168.31.166:4444/grid/register
浏览器输入http://localhost:4444/grid/console,可查看目前启动状态,
测试脚本,command_executor中输入远程地址端口即可在远程电脑运行自动化
from time import sleep from selenium import webdriver driver = webdriver.Remote(command_executor='http://192.168.1.217:5558/wd/hub', desired_capabilities={'browserName':'firefox'}) driver.get('https://www.baidu.com') driver.find_element_by_id("kw").send_keys("selenium") driver.find_element_by_id("su").click() sleep(1) driver.get_screenshot_as_file("baidu_img.png") driver.quit()