Facebook
Twitter
LinkedIn
YouTube
GitHub
Hasan's Blog
  • General
  • CI/CD
  • DevOps
  • Test Mgmt & Automation
  • Blog
    • About me

fill form using xpath in casperjs

2014/10/09Hasan NaqviUncategorizedNo comments

fill form using xpath in casperjs

 

<form method="post" name="hasanForm"><input id="ext-gen1089" name="userName" size="20" type="text" /> <input id="ext-gen1091" name="password" size="20" type="password" /> <button id="button-1054-btnEl">submit</button></form>
casper.test.begin('Test', 1, function suite(test) {
	casper.start("http://localhost/index2.html",function(){
	  	casper.userAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.66 Safari/537.36');
	});
	var x = require('casper').selectXPath;
	var fields = {};
	casper.then(function(){
	  casper.test.comment("locating form in html");
	casper.test.assertExists(x('.//form[@name="hasanForm"]'));

	/** Creating an array to store form data*/
		
			/** Filling array with form data */
		fields['//*[@id="ext-gen1089"]'] = "first text box";
		fields['//*[@id="ext-gen1091"]'] = "second text box";
		
		/** Passing the data array to the full to store data in the form 
		 *  To capture the form with data, we donot submit the form by passing 
		 *  false signal in third paramter of fillXPath function 
		 *  */
		this.fillXPath('form[name="hasanForm"]', fields, false);
		this.capture("Screenshotbefore_submit.png");
	});
	casper.then(function(){
	// you can use fillxpath again using third parameter true to submit the form
		//this.fillXPath('form[name="hasanForm"]', fields, true);
	this.click(x(".//*[@id='button-1054-btnEl']"));

	});
casper.then(function(){
	
	this.capture("Screenshotafter_submit.png");
});
	casper.run(function(){
		test.done();
	});
});

Related Posts:

  • When Scrum can fail?
  • How To Install Java with Apt-Get on Ubuntu 16.10
  • Port 80 is being used by SYSTEM (PID 4)
  • Error message when I run sudo: unable to resolve host

Share this:

  • Twitter
  • Facebook

Related

Previous post java.lang.IllegalArgumentException: Object: myjpaapp.entities.Staff@b524a9d is not a known entity type. Next post How to install Gnu parallel in linux

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Hasan Naqvi

Categories

  • Casperjs (1)
  • CI/CD (4)
  • DevOps (6)
  • Gruntjs (2)
  • Jira (1)
  • Linux (1)
  • Programming (1)
  • Uncategorized (14)
  • VMware (1)

Archives

  • May 2020 (1)
  • April 2020 (1)
  • March 2020 (2)
  • September 2019 (2)
  • May 2018 (1)
  • September 2017 (3)
  • July 2017 (1)
  • June 2017 (4)
  • May 2017 (1)
  • July 2015 (2)
  • January 2015 (1)
  • October 2014 (1)
  • September 2014 (5)
  • August 2014 (1)

Tags

Arduino Arduino sketch Arduino sketch upload bash shell casperjs Couchdb Curl docker container docker images github Gitlab gnu Parallel gruntjs JAVA JAVA jenkins Jira JPA Json Linux linux mint Maven mint MYSQL Tomcat Ubuntu Version Control xpath

Top Posts & Pages

  • CURD functions and REST api
  • How to completely uninstall Android Studio on MAC?
  • Before you can run vmware several modules must be compiled and loaded into the running kernel
  • Trying to upload Blink example (Arduino sketch) on my Arduino uno
  • fill form using xpath in casperjs
  • Delete docker images & containers in one command
  • How to import data in couchdb using JSON file

Subscribe to Blog via Email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

  • General
  • CI/CD
  • DevOps
  • Test Mgmt & Automation
  • Blog
    • About me
@2017