Search code examples
rubyphantomjscucumberwatirwatir-webdriver

PhantomJs Could Not Find Element Like Chrome Driver Using Watir WebDriver


I am having difficulties when using PhantomJs in my Watir webdriver.

Here is my code when selecting an element:

signInButton = driver.button text: 'Sign In'
signInButton.wait_until_present
signInButton.exists?
signInButton.click

It works fine when using Chrome but does not work when using PhantomJs.

This is how I start using Chrome:

@@driver = Watir::Browser.new :chrome, :switches => %w[--ignore-certificate-errors --disable-popup-blocking --disable-translate --disable-notifications --start-maximized]
@@driver.driver.manage.timeouts.implicit_wait = 100 # seconds

This is how I start using PhantomJs:

args = %w{--ignore-ssl-errors=true}
@@driver = Watir::Browser.new :phantomjs, :args => args
@@driver.driver.manage.timeouts.implicit_wait = 100 # seconds

Please help and thanks in advance.


Solution

  • PhantomJS is being deprecated in Watir & Selenium. Chromedriver has for a while been significantly faster, and now has implemented a Headless mode if you really need to have it be headless. Just add --disable-gpu and --headless to your array of switches.