7

When using the alert methods of selenium-webdriver, I encountered the JavaScript Error: "e is null"

Code:

browser = Watir::Browser.new :firefox
browser.alert.ok; sleep 5

Error:

Selenium::WebDriver::Error::UnknownError: [JavaScript Error: "e is null" {file: "file:///var/folders/f4/rz3xgqkj22zdyldyzrnyx4v40000gn/T/webdriver-profile20140731-47367-tyngix/extensions/fxdriver@googlecode.com/components/command_processor.js" line: 7716}]'
[JavaScript Error: "e is null" {file: "file:///var/folders/f4/rz3xgqkj22zdyldyzrnyx4v40000gn/T/webdriver-profile20140731-47367-tyngix/extensions/fxdriver@googlecode.com/components/command_processor.js"
line: 7716}]' when calling method: [nsICommandProcessor::execute]

Environment:

  • 'selenium-webdriver', '2.42.0'
  • Firefox 31.0
  • MAC 10.9
  • Ruby 2.0

Any advice would be very much appreciated. Thanks!

Rodion
  • 103
  • 1
  • 7
  • 1
    Does an alert exist on the page? These javascript errors are related to the WebDriver API included within Firefox. What version of Watir-Webdriver are you using? – Sonja Leaf Aug 01 '14 at 18:15
  • Yes alert exists on the page. I use gem 'watir-webdriver' - 0.6.10 Any idea how to deal with this? – Rodion Aug 04 '14 at 20:17
  • Can you include the HTML of the page and the ruby code that causes the error? When I run your provided code, I get a `Watir::Exception::UnknownObjectException` pointing to Watir-Webdriver code because no alert exists when running your code sample. – Sonja Leaf Aug 05 '14 at 17:08
  • `browser = Watir::Browser.new :firefox new_new = Onepage.new(:browser => browser) new_new.browser.alert.ok` Did not manage to fix this yet... – Rodion Sep 23 '14 at 00:00
  • Without the HTML, it is difficult to determine what the error may be. – Sonja Leaf Sep 24 '14 at 01:56

4 Answers4

1

Mine was caused by JavaScript alerts. There's an Ajax date picker that intermittently partially renders. While this is something that should be corrected in the application, in the mean time, I can handle it with:

try{
    driver.findElement(By.xpath("//span")).click();
   } catch (UnhandledAlertException uae) {
    driver.switchTo.alert().accept();
    driver.findElement(By.xpath("//span")).click();
   }

I'd also like to point out that I'm using WebDriver, so syntax may vary.

  • I'd like to follow up. This answer partially fixed the problem. I also had to add Thread.sleep(6000) and InterruptedException to each connected method. I think you're using Ruby, so there may be an equivalent that you can reference elsewhere. –  Sep 30 '14 at 21:58
1

So this isnt what you want to hear but this is my super hacky solution:

  target=browser.ul(:id => 'editor_sections').li(:index => j)
  target.drag_and_drop_by -300,200
  begin
    browser.button(:id => 'editor_panel_save').when_present.click
    puts "clicked save for module sidebar"
  rescue => e
    begin
      browser.alert.ok
      puts Thread.current["name"].white.on_red + ": No events for the " +sectionName + " module"
    rescue => e
    end
  end

As you can see the drag and drop event for me causes a jquery alert. I had the same problem as you did with the browser.alert.ok not always working. So I just wrapped it in an additional begin >> rescue block. The browser.alert.ok is actually called and the alert is dismissed AND that pesky random e is null error is ignored.

If anyone has an actual solution I'd love to see it.

cpoole
  • 346
  • 3
  • 5
0

I am not sure about the Watir syntax, but following is the Java code to deal with Alerts.

Alert alert=driver.switchTo().alert();
alert.accept();
Uday
  • 1,433
  • 10
  • 36
  • 57
-4

We can't really answer this since the problem is in your javascript code (which is not attached).

Selenium::WebDriver::Error::UnknownError: [JavaScript Error: "e is null" {file: "file:///var/folders/f4/rz3xgqkj22zdyldyzrnyx4v40000gn/T/webdriver-profile20140731-47367-tyngix/extensions/fxdriver@googlecode.com/components/command_processor.js" line: 7716}]'

Problem is in command_processor.js on line 7716.

Gord
  • 1,805
  • 3
  • 17
  • 22