Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 97771

Why does the browser close automatically after the tasks are executed when I'm using selenium with Ruby?

$
0
0

I'm starting to learn Ruby along with selenium and cucumber: I'm running on ubuntu and using Firefox as a browser Ubuntu: Description: Ubuntu 18.04.3 LTS Release: 18.04

Firefox version: 72.0.1 selenium-webdriver version : 3.142.7 Ruby version: 2.5.1p57

I've started with a small simple test:

require 'rubygems'
require 'selenium-webdriver'

driver = Selenium::WebDriver.for :firefox
driver.get "http://google.com"
element = driver.find_element(name: "q")
element.send_keys "Cheese!"
element.submit

After "Cheese" is submitted to the search bar, the browser closes immediatly.

I want to leave it open so what can I do ? I have found this suggested solution :

caps = Selenium::WebDriver::Remote::Capabilities.firefox(:firefox_options => {detach: true})
driver = Selenium::WebDriver.for :firefox, desired_capabilities: caps

But when I add it to my code I get this deprecation warning:

2020-01-23 10:12:35 WARN Selenium [DEPRECATION] :firefox_options capabilitiy is deprecated. Use Selenium::WebDriver::Firefox::Options instead.

I tried using Options but haven't succeeded because I must've done it wrong. Here's what I have done

opt = Selenium::WebDriver::Firefox::Options.new
opt.add_preference("detach","true")
caps = Selenium::WebDriver::Remote::Capabilities.firefox(opt)
driver = Selenium::WebDriver.for :firefox, desired_capabilities: caps

I get the following error:

`firefox': undefined method `key?' for #<Selenium::WebDriver::Firefox::Options:0x000055e1a6c58158> (NoMethodError)

Viewing all articles
Browse latest Browse all 97771

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>