问题
Discription
I want to attach selenium to existing session of chrome, and then tweak pages using my chrome profile, but from terminal I have found that this is feasible using debuggerAddress
Excerpt -
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();
Steps to reproduce -
// 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
回答1:
The ruby client doesn't have add_experimental_option.
Use add_option instead:
options = Selenium::WebDriver::Chrome::Options.new
options.add_option("debuggerAddress", "127.0.0.1:4444")
来源:https://stackoverflow.com/questions/45400113/selenium-ruby-how-to-add-debuggeraddress-experimental-option