Monday, 5 June 2017

Selenium Webdriver Node.js : How to load and execute jQuery code

i'm using Selenium webdriver & Node.JS for functional testing.

i'm trying to use jquery code to do some treatment.

  1. First of all , i tried to include jquery and load it within :

    driver.executeScript("var s=window.document.createElement('script');\ s.src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js';\ window.document.head.appendChild(s);");

-> this treatment seems to be executed (since i'm not catching a related error)

  1. But when trying to use jquery functionalities , here is an example :

    driver.executeScript("$('#edit-submit').on('click',function(){alert('test');})");

    i'm catching this :

My error handler... WebDriverError: unknown error: $ is not a function

it seems that jquery is either not successfully loaded or i'm not using it properly.

Suggestions ?



via firasKoubaa

No comments:

Post a Comment