3

I am in the process of creating some BDD tests using Java, Cucumber & Selenium.

The problem I am having is the website I am attempting to test has been specifically designed to work with firefox and I have been asked to test it only on this browser. When I navigate to the page, firefox creates a popup asking for permission to store data on the computer for offline use. (See picture below)

FireFox alert

I am struggling to get selenium to recognise this alert and accept it.

So far I have attempted and failed at the following:

  • I have attempted to access the popup by attempting to access the window alert – this hasn’t worked and I had a null pointer.
  • I have also attempted capturing the preferences of the Firefox profile on my personal machine (after allowing the website to store information) and copy them into a profile within the selenium code. This also hasn’t worked.
  • I have also attempted creating an empty profile with just this preference set:

    firefoxProfile.setPreference("network.online", false);

The problem is the web page will not load any of its data till you accept this message. So any code I have created that tests the site always fails.

Has anyone else ever come across this issue before and if so how did you solve the problem?

I am using Selenium-Server 2.53.0 on windows 7 with java 7

1

1 Answer 1

1

I think this behavior is a global event and should be treat accordingly.

Consider use of https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/firefox/FirefoxProfile.html

some "code" would be:

1) create an instance of FirefoxProfile 2) use a setPreference method and pass in the instruction to disable dom beforeunload - it's a method that will take various argument types (check the docs in the link) 3) Instantiate your driver and pass the FirefoxProfile instance into it.

That should work, it worked for me.. however I am using latest JDK and latest JUnit

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.