Joe
Joe

Reputation: 2633

Firefox link redirection issue using selenium

I have an automation service I build and before you run the automation you give it a link so when you start the automation you get first redirect to this link.

On my machine you get redirected perfectly, but on a friend machine the Firefox browser is opened and thats it.

does anyone know what might be the issue?

here is the class that responsible for this:

case class csvUploadData(clientUrl: String)
  val csvUploadForm = Form(
    mapping(
      "clientUrl" -> nonEmptyText)(csvUploadData.apply)(csvUploadData.unapply))

  def uploadCSV = Action.async(parse.multipartFormData) { implicit request =>
    csvUploadForm.bindFromRequest.fold(
      formWithErrors => {
        Future {
          Redirect(routes.Application.index).flashing(
            "error" -> formWithErrors.error("clientUrl").get.message)
        }
      },
      userData => {
        request.body.file("csvFile").fold(Future {
          Redirect(routes.Application.index).flashing(
            "error" -> "Missing CSV file").withSession(request.session)
        }) { formFile =>
          import java.io.File
          val filename = formFile.filename
          Future {
            val file = formFile.ref.file
            val purchaseInfos = purchaseDS(file)

            val t = Try {
              val driver: WebDriver = new FirefoxDriver
              val actions: ActionsHMRC = new ActionsHMRC(driver, userData.clientUrl)

              val results = actions.insertData(purchaseInfos)
              results.filter(_._2.isFailure)
            }
            t match {
              case Success(failures) =>
                val failedMsg = if (failures.nonEmpty)
                  failures.map{case (pi, err) => s"${pi.invoiceNumber} -> ${err}}"}.mkString("The following rows failed: [\n","\n","\n\n\n]")
                else ""
                Redirect(routes.Application.index).flashing(
                "success" -> s"The file '$filename' automation successfuly.\n$failedMsg")
              case Failure(e) =>
                println(e)
                Redirect(routes.Application.index).flashing (
                "error" -> s"The file '$filename' automation failed.")
            }
          }
        }
      })
  }
}

I have ver 42.0 and he have 43.0.4

Upvotes: 0

Views: 1094

Answers (1)

Shubham Jain
Shubham Jain

Reputation: 17563

I think that's happening because the new issue occurs with latest update of Mozilla firefox.

It's happening with me too.

To overcome from this issue you need to setPreference as xpinstall.signatures.required", false to firefox Profile and then pass it to driver object

firefoxProfile.setPreference("xpinstall.signatures.required", false);

Below code is working fine for old selenium jars.

static WebDriver driver=null;
public static void main(String[] args) {
final FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("xpinstall.signatures.required", false);
driver = new FirefoxDriver(firefoxProfile);
driver.get("https://www.google.de/");

Thanks it really helps but one change FirefoxDriver(firefoxProfile) is not valid. instead FirefoxOptions as below:

final FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("xpinstall.signatures.required", false);
FirefoxOptions firefoxOptions = new FirefoxOptions();
firefoxOptions.setProfile(firefoxProfile);
driver = new FirefoxDriver(firefoxOptions);

Upvotes: 2

Related Questions