6

So probably the most important thing to preface this with is that I'm using c9. It's an IDE in the cloud and so that is giving me a lot of trouble when trying to use Chrome or Firefox with Watir, because I can't write a path to the Chrome or Firefox browser. I've also tried every variation of wait methods I could find but none of them work.

def save
    require 'watir'
    require 'phantomjs'

    @browser = Watir::Browser.new :phantomjs
    @browser.goto "https://kroger.softcoin.com/programs/kroger/digital_coupons/?origin=DigitalCoupons&banner=Smiths#contentBox"

    @browser.div(id: "contentBox").wait_until(&:present?).text
    @products = @browser.divs

end

Error

timed out after 30 seconds, waiting for true condition on #"contentBox", :tag_name=>"div"}>

The way I want to fix this problem of not being able to scrape data from the Smiths website is to use a chrome browser, but I get the error "unable to connect to chromedriver 127.0.0.1:9515"

ChrisWilson
  • 459
  • 1
  • 6
  • 19
  • It works properly in firefox and you don't have to use wait_until() method because it automatically waits for :exist :present :enabled . Please don't use geckodriver for firefox, use legacy firefox, it works very properly. – RAJ Sep 18 '17 at 06:32
  • 2
    Don't use legacy Firefox unless you absolutely have to; geckodriver is close to feature complete at this point. Legacy Firefox will likely not be an option in upcoming Selenium 4. Chrome Driver is best supported right now, check out `Watir::Browser.new :chrome, headless: true` as a replacement for phantomjs. It is much faster and phantomjs is being deprecated. – titusfortner Sep 18 '17 at 14:49
  • @titusfortner Do you know firefox restores it's support for selenium at 52 esp version? – RAJ Sep 19 '17 at 05:52
  • @titusfortner I've tried that before, but I get the error "unable to connect to chromedriver 127.0.0.1:9515", and I can't seem to link a path to the Chrome browser because I'm developing in an online IDE. – ChrisWilson Sep 21 '17 at 01:59

2 Answers2

3

I had similar problem and I resolved it by installing docker container with selenium

# docker-compose.yml file
version: '2'
services:
  selenium:
    image: selenium/standalone-chrome
    ports:
      - "4444:4444"
    restart: always
    volumes:
      - "${PWD}/spec:${PWD}/spec" # I exposed `spec` dir to cover code with specs
      - /dev/shm:/dev/shm


# test.rb file
@browser = Watir::Browser.new(
  :remote,
  url: 'http://localhost:4444/wd/hub'
)

Run container with command:

docker run -it -d -P -p 4444:4444 -v `pwd`/spec:`pwd`/spec selenium/standalone-chrome

And try again

(Also you can run container even on VPS or another remote server, and then connect to it)

itsnikolay
  • 17,415
  • 4
  • 65
  • 64
2

I had a similar issue and installing the webdrivers gem fixed my problem

$gem install webdrivers

Tony Vincent
  • 13,354
  • 7
  • 49
  • 68