gpt4 book ai didi

selenium - 从 Java 进程运行 Selenium

转载 作者:行者123 更新时间:2023-12-02 05:56:06 24 4
gpt4 key购买 nike

您如何从 Java 进程运行 Selenium 进程(线程),这样我就不必手动启动 Selenium?

最佳答案

服务器:

import org.openqa.selenium.server.SeleniumServer;
public class SeleniumServerControl {
private static final SeleniumServerControl instance = new SeleniumServerControl();
public static SeleniumServerControl getInstance() {
return instance;
}
private SeleniumServer server = null;
protected SeleniumServerControl() {
}
public void startSeleniumServer() {
if (server == null) {
try {
server = new SeleniumServer(SeleniumServer.DEFAULT_PORT);
System.out.println(" selenium server " + server.toString());
} catch (Exception e) {
System.err.println("Could not create Selenium Server because of: "
+ e.getMessage());
e.printStackTrace();
}
}
try {
server.start();
} catch (Exception e) {
System.err.println("Could not start Selenium Server because of: "
+ e.getMessage());
e.printStackTrace();
}
}
public void stopSeleniumServer() {
if (server != null) {
try {
server.stop();
server = null;
} catch (Exception e) {
System.err.println("Could not stop Selenium Server because of: "
+ e.getMessage());
e.printStackTrace();
}
}
}
}

客户端:

browser = new DefaultSelenium("localhost", 4444, "*firefox", "http://www.google.com");
browser.start();

关于selenium - 从 Java 进程运行 Selenium,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/321112/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com