描述
我想将硒附加到现有的 chrome 会话,然后使用我的 chrome 配置文件调整页面,但从终端 我发现使用调试器地址这是可行的
摘录-
Launch Chrome from command prompt:
chrome.exe --remote-debugging-port=8181
Sample Code:
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("debuggerAddress", "127.0.0.1:8181");
WebDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(1, TimeUnit.MINUTES);
driver.get("http://www.google.com");
driver.findElement(By.name("q")).sendKeys("test");
driver.quit();
重现步骤 -
// close all chrome windows
$ google-chrome-stable --remote-debugging-port=4444
// chrome opened with my profile
$ pry
> require 'selenium-webdriver'
> Selenium::WebDriver::Chrome.path = '/usr/bin/google-chrome-stable'
> Selenium::WebDriver::Chrome.driver_path = '/usr/bin/chromedriver'
> options = Selenium::WebDriver::Chrome::Options.new
> # options.add_experimental_option("debuggerAddress", "127.0.0.1:4444") # how????
> driver = Selenium::WebDriver.for :chrome, options: options
ruby 客户端没有add_experimental_option
。
请改用add_option
:
options = Selenium::WebDriver::Chrome::Options.new
options.add_option("debuggerAddress", "127.0.0.1:4444")