2

I've been having some issues when using selenium webdriver with PhantomJS.

I get the impression that the different actions aren't executing on the page itself. If I try running something that changes an element on the page and the test executes fully without any errors, and afterward open the page in a regular browser the element edited does not seem to have changed.

1 Answers1

0

Verify that the methods that should be triggered by the actions are truly not executed. You can do it like this:

First, override the method to "inject" some flag that would be triggered by the action (it's Scala code, but you should get the idea):

val js: JavascriptExecutor = webDriver.asInstanceOf[JavascriptExecutor]
js.executeScript(myScript)

  lazy val myScript: String = {
    s"""
      window.openNewWindowFlag = false;

      SDK.openNewWindowFlag = function(url, width, height, onClose) {
        openNewWindowFlag = true;
      };
      """
  }

Note, we adding the flag on the global (window) scope. Then, run the action that should call some method (the one we override) and check if the flag changed:

val js: JavascriptExecutor = webDriver.asInstanceOf[JavascriptExecutor]
val isMethodTriggered = js.executeScript("return openNewWindowFlag").toString.toBoolean
Johnny
  • 14,397
  • 15
  • 77
  • 118