使用Selenium JS连接到Geckodriver [英] Connect to geckodriver with selenium js
问题描述
我不是Selenium的专家,所以我在这里可能会错过一些事情.
I'm not an expert of Selenium, so I may miss something here.
- 公司中的一种软件使用Geckodriver启动了Firefox.
- 我想通过我的JavaScript代码连接/连接到该浏览器.
我知道Web服务器启动的端口和会话标识符.
I know the port where the Webserver starts and the sessions identifier.
我尝试通过JS连接:
const webdriver = require('selenium-webdriver')
void async function() {
let driver = await new webdriver.Builder().forBrowser('firefox').usingServer('http://localhost:55849/').build();
await driver.get('http://www.google.com/ncr');
await driver.findElement(By.name('q')).sendKeys('webdriver');
await driver.findElement(By.name('btnG')).click();
await driver.wait(until.titleIs('webdriver - Google Search'), 1000);
driver.quit();
}();
连接失败.我能想到的是,这段代码试图启动一个新实例.
The connection is not successful. What I can think is that this code tries to start a new instance.
有错误消息:
SessionNotCreatedError: Session is already started
有什么想法可以连接到现有的吗?并控制它?
Any idea how I can connect to the existing one? And control it?
我已经尝试了文档中的所有内容: https://www.npmjs.com/包/selenium-webdriver
I've tried everything from the docs: https://www.npmjs.com/package/selenium-webdriver
我什至尝试连接 http://localhost:55849/wd/hub
,但是随后我收到了 WebDriverError:HTTP方法不允许
错误
I even tried to connect http://localhost:55849/wd/hub
but then I received WebDriverError: HTTP method not allowed
error
推荐答案
使用 查看全文