Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • NodeJS Tutorial
  • NodeJS Exercises
  • NodeJS Assert
  • NodeJS Buffer
  • NodeJS Console
  • NodeJS Crypto
  • NodeJS DNS
  • NodeJS File System
  • NodeJS Globals
  • NodeJS HTTP
  • NodeJS HTTP2
  • NodeJS OS
  • NodeJS Path
  • NodeJS Process
  • NodeJS Query String
  • NodeJS Stream
  • NodeJS String Decoder
  • NodeJS Timers
  • NodeJS URL
  • NodeJS Interview Questions
  • NodeJS Questions
  • Web Technology
Open In App
Next Article:
How to test the id of an element using Protractor ?
Next article icon

How to get x and y coordinates of an element in protractor Node.js ?

Last Updated : 12 Apr, 2023
Comments
Improve
Suggest changes
Like Article
Like
Report

Protractor is an end-to-end test framework that is developed for AngularJS and Angular applications. It basically runs the tests against the application which is interacting with it as a real user would, running in a real browser. In the following example, we are going to get the x and y coordinates of an element and check if it is as expected or not.

Pre-requisite: Installation and Setup of Protractor

Approach:

  • We are going to create a basic test program in which we are going to check whether the x and y coordinates of an element is as expected or not.
  • All the Protractor tests will have a file containing the configuration and this file will be the initial file that will initiate the test.
  • Let's create this file with the name conf.js.

Example: Filename: conf.js

JavaScript
exports.config = {      // Capabilities values for     // webdriver instance     capabilities: {         'browserName': 'chrome'     },      // Framework value     framework: 'jasmine',      // The Spec patterns are relative to the      // current working directory when     // protractor is called.     specs: ['test.js'],      // Options which are passed to our     // framework ie. Jasmine.     jasmineNodeOpts: {         defaultTimeoutInterval: 30000     },      // File URL     baseUrl: 'file://' + __dirname + '/',      onPrepare: function () {         browser.resetUrl = 'file://';     } }; 

Now let's create our HTML file called test.html which will contain the element to be tested.

Filename: test.html

HTML
<!DOCTYPE html> <html lang="en"> <body>     <!-- The element to be tested -->     <div id="foo" style="position: absolute;         top:20px; left: 15px">         Inner text     </div> </body> </html> 

Now let's create our test file test.js. In this file, we are going to access an HTML file and then get the x and y coordinates and will check if it is as set in the HTML file or not. Browser is a global created by Protractor.

Jasmine framework provides the describe() function and it() function where the describe is a description of your test while it is the steps for the test.

Filename: test.js

JavaScript
describe('Protractor Demo App', function () {     it('should have a title', function () {         // Disabling waiting for angular         browser.waitForAngularEnabled(false)          // Get our html file for testing         browser.get('test.html');          // Test if the element have required coordinates         let foo = element(by.id('foo'));         expect(foo.getLocation()).toEqual(         jasmine.objectContaining({             x: 15,             y: 20         }));     }); }); 

Run the conf.js file using the following command:

protractor conf.js

Output:


Next Article
How to test the id of an element using Protractor ?
author
gurrrung
Improve
Article Tags :
  • Web Technologies
  • HTML
  • Node.js
  • NodeJS-Questions

Similar Reads

  • How to get the coordinates of a mouse click on a canvas element ?
    The coordinates of the mouse whenever a click takes place can be found by detecting the click event with an event listener and finding the event's x and y positions. In this article we are going to learn How to get the coordinates of a mouse click on a canvas element. ApproachCreate a JavaScript fun
    2 min read
  • How to get text from an element and store in a variable in Cypress?
    In Cypress, it's common to retrieve the text content from an element and use it for further actions or assertions. To store the extracted text in a variable for later use, Cypress provides commands like .then() or .invoke(), allowing you to handle the value outside of the usual Cypress chain. In thi
    3 min read
  • How to test the id of an element using Protractor ?
    Protractor is an end-to-end test framework developed for Angular and AngularJS applications. It runs tests against the application interacting with it as a real user would, running in a real browser. In this article, we are going to test the id of an element. Pre-requisite: Installation and Setup of
    2 min read
  • How to use protractor to check if an element is visible ?
    Protractor is an end-to-end test framework developed for AngularJS applications, however, it also works for non-Angular JS applications. It runs tests against the application interacting with it as a real user would, running in a real browser. In this article, we are going to use Protractor to check
    3 min read
  • How to test CSS property of an element using Protractor ?
    Protractor is an end-to-end test framework developed for Angular and AngularJS applications. It run tests against the application interacting with it as a real user would, running in a real browser. In this article, we are going to test the CSS property of an element. Pre-requisite: Installation and
    3 min read
  • JavaScript - How to Get the Data Attributes of an Element?
    Here are the various methods to get the data attributes of an element using JavaScript 1. Using dataset PropertyThe dataset property in JavaScript allows you to access all data attributes of an HTML element as a DOMStringMap object. It simplifies retrieving, modifying, or interacting with custom dat
    2 min read
  • How to Detect if Node is Added or Removed Inside a DOM  Element?
    Detecting the nodes when they are added or removed from the DOM (Document Object Model) element is a common requirement in web development. It allows developers to respond dynamically to the changes in the DOM structure enabling features such as live updates, event delegation, and more. You can util
    3 min read
  • How to test the name of tag of an element using Protractor ?
    Protractor is an end-to-end test framework developed for Angular and AngularJS applications. It runs tests against the application interacting with it as a real user would, running in a real browser. In this article, we are going to test the name of the tag of an element. Pre-requisite: Installation
    2 min read
  • How to Get and Set Scroll Position of an Element using JavaScript ?
    In this article, we will learn how to get and set the scroll position of an HTML element using JavaScript. Approach: We will be using the HTML DOM querySelector() and addEventListener() methods and the HTML DOM innerHTML, scrollTop and scrollLeft properties. We create an HTML div element with an id
    3 min read
  • How do I get Cypress just to process the visible element?
    When writing Cypress tests, you might encounter elements that are either hidden by default or not visible due to styling (like display: none). To avoid Cypress trying to interact with such elements, you can leverage the .should('be.visible') command. This assertion guarantees that the test will only
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences