How to deal with JavaScript Error: "e is null" when try to click on browser pop-up in Firefox
Asked Answered
S

4

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/[email protected]/components/command_processor.js" line: 7716}]'
[JavaScript Error: "e is null" {file: "file:///var/folders/f4/rz3xgqkj22zdyldyzrnyx4v40000gn/T/webdriver-profile20140731-47367-tyngix/extensions/[email protected]/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!

Spleen answered 31/7, 2014 at 20:4 Comment(5)
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?Glooming
Yes alert exists on the page. I use gem 'watir-webdriver' - 0.6.10 Any idea how to deal with this?Spleen
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.Glooming
browser = Watir::Browser.new :firefox new_new = Onepage.new(:browser => browser) new_new.browser.alert.ok Did not manage to fix this yet...Spleen
Without the HTML, it is difficult to determine what the error may be.Glooming
U
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.

Ussery answered 30/9, 2014 at 16:6 Comment(1)
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.Ussery
D
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.

Delcine answered 26/11, 2014 at 5:47 Comment(0)
B
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();
Bocock answered 4/8, 2014 at 10:1 Comment(1)
Yes, the error is caused by browser.alert.ok which makes it a bit unusual case.Spleen
R
-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/[email protected]/components/command_processor.js" line: 7716}]'

Problem is in command_processor.js on line 7716.

Reichsmark answered 31/7, 2014 at 20:26 Comment(2)
I know, but I think that file is a part of WatirWebDriver. Any other idea?Spleen
This JS error is from the WebDriver extension included within Firefox.Glooming

© 2022 - 2024 — McMap. All rights reserved.