0

Can anyone please tell me how to use jQuery with selenium-webdriver to scrape some web page with Node.JS

My current code looks like this

driver.get(args.bookingURL).then(function () {
                return driver.executeScript("\
                    $('#customer_login_email').val('sonetsobuj@gmail.com');\
                    $('#customer_login_password').val('*******');\
                    ");
            }).then(function () {
                console.log('Button Will be Clicked');
                return driver.executeScript("$('#customer_login').click();");
            });

When I execute this script terminal shows this

JavascriptError: $ is not defined

Shafayat Alam
  • 702
  • 1
  • 14
  • 32
  • have u tried by removing \ ? – noor Jul 27 '16 at 14:27
  • I don't think the problem is related to that, I did not integrate jquery with selenium-webdriver anywhere, I needed to know how I can do that. Thanks though :) – Shafayat Alam Jul 27 '16 at 14:30
  • Exception clearly says your website does not support jquery....have you tried to run provided JavaScript in browser console manually?? – Saurabh Gaur Jul 27 '16 at 14:31

2 Answers2

1

use the script like below:

driver.executeScript("$('#customer_login_email').val('sonetsobuj@gmail.com'); "
            + "$('#customer_login_password').val('*******');");
    }

when you enter script in new line you have to add an extra + in your script.

u can go through this page to check how to add jquery in DOM https://sqa.stackexchange.com/questions/2921/webdriver-can-i-inject-a-jquery-script-for-a-page-that-isnt-using-jquery

Community
  • 1
  • 1
noor
  • 2,954
  • 2
  • 16
  • 29
0

this is how I added jQuery

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);");

Hope it helps someone.

Shafayat Alam
  • 702
  • 1
  • 14
  • 32