Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In Protractor, pass a locator created with by to element() to find one element, or to element.all() to find a collection. For example, element(by.id('save')) finds an element by ID, while element(by.css('button.save')) uses a CSS selector. Protractor also has AngularJS-specific locators such as by.model() and by.binding(), but those are not suitable for every Angular application. Protractor reached end-of-life in August 2023, so this guide is intended for maintaining existing tests, not choosing a framework for a new project.

How Protractor locators work

A locator describes how to identify an element in the page’s DOM. Protractor’s by object builds locator objects, and element(locator) wraps one in an ElementFinder that your test can interact with. Use element.all(locator) when the intended result is a collection rather than one element.

// One element found by a standard WebDriver locator
const saveButton = element(by.id('save'));

// A collection found by a standard WebDriver locator
const rows = element.all(by.css('table.orders tbody tr'));

The examples show Protractor syntax; they are not claims of live testing. The exact interaction you perform after locating an element depends on the test and the element, but the locator itself only specifies how to find it.

Standard Selenium locator strategies in Protractor

Protractor supports the traditional WebDriver locator strategies. These work from DOM attributes, text, or element type rather than AngularJS-specific concepts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Strategy Example What it targets
ID by.id('save') An element with id="save".
CSS selector by.css('button.save') An element matching the CSS selector.
Class name by.className('save') An element with the specified class name.
Name by.name('email') An element with name="email".
Link text by.linkText('Continue') A link whose text matches the supplied text.
Partial link text by.partialLinkText('Cont') A link whose text contains the supplied text.
Tag name by.tagName('button') Elements of the specified HTML tag.
XPath by.xpath("//input[@name='email']") An element matched by the XPath expression.

These are the conventional WebDriver strategies documented by Selenium. Protractor’s AngularJS-aware helpers are additional locator options, not another name for the standard strategies.

Write and use common locator examples

Find a single element

Use element() when your test expects one intended match. The following examples show an ID, a readable CSS selector, and an XPath expression:

const saveButton = element(by.id('save'));
const checkoutForm = element(by.css('form.checkout'));
const emailField = element(by.xpath("//input[@name='email']"));

Once you have an ElementFinder, use the interaction appropriate to your test. If the locator matches more than one element, do not rely on an accidental first match; make the selector more specific or use a collection and handle the intended result explicitly.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Find a collection

Use element.all() for repeated content, such as table rows or a list of results. The Protractor tutorial also demonstrates this collection pattern with a repeater locator:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const todoItems = element.all(by.repeater('todo in todoList.todos'));
const orderRows = element.all(by.css('table.orders tbody tr'));

For repeated page structures, a scoped child lookup can make the target clearer than a long page-wide selector. Keep the parent and child relationship understandable, and make your test state which matching item it intends to use.

Use AngularJS-aware locators only where they apply

Protractor’s locator model includes helpers that describe AngularJS concepts. For example, the Protractor tutorial shows by.model('first') for an element with ng-model="first", and by.binding('latest') for content bound to latest.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
// AngularJS-oriented examples
const firstNumber = element(by.model('first'));
const latestValue = element(by.binding('latest'));
const todos = element.all(by.repeater('todo in todoList.todos'));

Do not assume that by.model() or by.binding() works in every Angular application. The Protractor project says these locators are not supported for Angular applications and recommends by.css; the model and binding examples in its tutorial describe AngularJS. If your application is not using the AngularJS behavior those helpers expect, use a suitable standard locator such as CSS.

Choose locators that survive markup changes

Selenium’s locator guidance recommends a unique, predictable ID when one is available. If there is no suitable ID, prefer a well-written CSS selector. XPath can express more complex relationships, but Selenium notes that XPath may be difficult to debug and can be slow. Treat that as documentation guidance, not as a claim that a particular locator will be slower in your application.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Prefer a unique ID when it is stable and identifies the intended element.
  • Otherwise, use a readable CSS selector tied to useful, stable markup.
  • Use XPath when its expressive power solves a real selection problem, rather than defaulting to a long positional path.
  • Keep selectors compact and understandable so failures are easier to diagnose.
  • When several elements share a pattern, use element.all() and make the intended match explicit.

As a practical application of the stability and readability guidance, favor selectors tied to meaningful attributes or structure over selectors that depend on a fragile position in the page.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Troubleshoot locator failures

The locator finds no element

  • Check that the selector matches the rendered DOM, including spelling, capitalization, and attribute values.
  • Confirm whether the target is present at the moment the test performs the lookup; a correct selector cannot find an element that has not appeared.
  • If using an AngularJS-specific helper, verify that the page and locator actually use the corresponding AngularJS concept. For modern Angular applications, the project recommends CSS rather than model or binding locators.

The locator finds the wrong element or multiple elements

  • Check whether the chosen ID is genuinely unique or the CSS/XPath selector is too broad.
  • For repeated components, scope the lookup to the intended parent and use a collection when multiple matches are expected.
  • Avoid depending on a positional selector unless position is itself part of the intended behavior.

The selector is hard to debug

  • Replace a long or deeply positional XPath with a shorter stable ID or CSS selector when possible.
  • Break down which part of the selector identifies the wrong ancestor, attribute, or child.
  • For a repeated structure, first identify the relevant container, then locate the target within that scope.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Protractor status and migration context

The official Protractor site states: “Protractor reached end-of-life in August 2023.” Teams maintaining existing suites can continue to use their current locator patterns as part of that maintenance, but the lifecycle status is important when deciding where to invest in new tests.

The project’s migration discussion describes Selenium WebDriver as one of the closest options in API terms while cautioning that methods are not exact one-to-one replacements. Playwright’s migration guide maps familiar locator forms, including CSS, ID, model-attribute CSS, repeater-attribute CSS, and XPath. Those mappings can help orient a migration, but they do not make a framework switch automatic: review behavior, synchronization, and the surrounding test code as well as the locator syntax.

Or skip the browser setup

If what you need is a rendered screenshot rather than a Protractor locator test, ScreenshotNeo is a website screenshot API. One GET request can return a PNG, JPEG, WebP, or PDF; it is separate from Protractor and does not replace a browser test.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

For example, this cURL request captures a page as WebP. See the ScreenshotNeo API documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
  • Cookie and consent banners are accepted before capture, and more than 60 known consent platforms, newsletter popups, and chat widgets are removed; each step can be turned off.
  • Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed. Responses identify the page verdict and billing status in headers.
  • An MCP server offers take_screenshot, get_page_info, and capture_pdf for AI agents and MCP clients.
  • The free plan includes 1,000 shots per month without a card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.