Phone Batteries Are Better Than Ever. Why Doesn’t It Feel That Way?


On a recent trip to Disneyland, amid churro breaks, Spider-Man selfies and bouncing between rides at “the happiest place on Earth,” I was gripped by a very real-world anxiety: I kept checking my phone’s battery level. 

Even with an iPhone 17 Pro Max, which topped CNET’s battery tests, I couldn’t shake the feeling. After snapping photos, tracking ride wait times, mobile-ordering food and messaging friends, I depleted half my charge by mid-afternoon. 

Worried about my phone making it through the day, I turned on Low Power Mode. I even carried a battery pack to ease my mind. I wrapped up the evening after filming the World of Color light-and-water show with a modest 36%. Not bad, but cutting it closer than I’d prefer.

These days, our phones can do almost anything. Just not for very long.

As smartphones have grown more advanced — doubling as high-definition cameras, GPS systems, digital wallets and AI assistants — one feature that often fails to impress is battery life. If there’s a single thing you can guarantee at the end of each day, it’s that you’ll need to plug in your phone.

A new CNET survey found that 58% of smartphone owners are frustrated with their device’s battery life. More than half of respondents say that dissatisfaction with their batteries would drive them to upgrade. That tops a desire for more storage (38%), new camera features (27%) and a better display (22%).

That’s not to say today’s smartphone batteries are bad. In fact, understanding the constraints and capabilities of the lithium-ion batteries powering our handheld devices might require a bit of reframing. If anything, it’s remarkable that they can keep pace with our growing demands — especially as our lives become increasingly digital and our screen time surges

Even if you don’t notice it, the battery powering your phone has steadily become more efficient and robust with each device upgrade. 

“As our phones have gotten better, they get more and more power-hungry,” says Celina Mikolajczak, an adviser and longtime executive in the battery industry. “The batteries keep getting better, but we keep wanting more.”

Still, manufacturers are racing to meet consumer demand for batteries that last well beyond a single day. In China, brands like Honor, Huawei and Oppo are outfitting their devices with silicon-carbon batteries, which offer higher energy density and faster charging than many existing phone batteries. In CNET’s lab testing, nearly half of the phones with the best battery life use silicon-carbon tech.

Major players in the US market, such as Apple, Samsung and Google, have yet to adopt these newer battery designs in their handsets, though it may not be long before they do. Motorola, owned by Chinese parent company Lenovo and headquartered in Chicago, has equipped its latest Razr lineup with silicon-carbon batteries, potentially setting the stage for more US-based brands to follow suit.

But bringing these new technologies to market is no small feat. Advancements need to be validated across millions of units to avoid unexpected failures, safety concerns and performance issues at scale, says Paul Braun, director of the Materials Research Laboratory at the University of Illinois at Urbana-Champaign.

“You want to change the world,” he says, “you have to be able to do it in world quantities.”

The rise of silicon-carbon batteries

At a press roundtable for Samsung’s Galaxy S26 launch in February, the line of questioning quickly shifted from what was new — AI features, camera improvements and display upgrades — to what wasn’t. Why hasn’t Samsung equipped its phones with more energy-dense silicon-carbon batteries, as so many Chinese brands have?

Samsung Executive Vice President Sung-hoon Moon said the company is still assessing whether to adopt the emerging battery technology. Ongoing tests have to ensure that silicon-carbon meets Samsung’s standards for battery life and charging speed, he noted. 

Zooey Liao/CNET/Getty Images

“In the end, what’s important is the user experience,” Moon said via a translator. “If it passes all our internal requirements and if it’s demonstrated that it can enhance user experience, then yes, perhaps someday.”

Like other large-scale phone manufacturers, Samsung doesn’t want to take unnecessary risks — especially after the Galaxy Note 7‘s disastrous launch and ultimate recall in 2016, when multiple phone batteries overheated and exploded

“These guys are being conservative, they’re being careful and they’re being cognizant of who their customers are,” Mikolajczak says.

The first commercial lithium-ion battery was released in 1991 and eventually became a staple in consumer electronics like laptops and phones, as well as in electric vehicles and power tools. The appeal is broad: Lithium-ion batteries can store a lot of energy for their size and weight, charge relatively quickly and withstand hundreds to thousands of charge cycles without significant degradation. 

They’re also highly efficient, wasting little energy during charging and discharging. Plus, they retain most of their charge when not in use, so a powered-off device is ready to go when you turn it back on. And because manufacturers can now produce lithium-ion batteries at massive scale, costs are relatively low, making devices more affordable.

“Lithium-ion batteries are a proven asset,” Braun says. “If you are going to be selling millions of phones, reliability, safety and consistency are critical.”

Lithium-ion batteries in your phone have an anode (the negative electrode) and a cathode (the positive electrode). A thin membrane, called a separator, keeps them from touching while still allowing lithium ions to pass through an electrolyte solution. When you use your device, lithium ions move from the anode to the cathode, while electrons flow through the phone’s circuitry. This flow of electrons powers the device.

Silicon-carbon batteries aren’t an entirely new type of battery, but rather a next-generation version of lithium-ion technology. Put simply, instead of using graphite in the battery’s anode, manufacturers incorporate a silicon-carbon composite. 

Because silicon can hold more lithium than graphite, this design allows for higher energy density, which can mean longer battery life and possibly faster charging. Manufacturers add carbon to the silicon because silicon expands and contracts significantly when charging, which can degrade the battery more rapidly. Carbon serves as a buffer and stabilizer, helping extend a battery’s lifespan while also storing lithium.

quote-1.png

In the US and many parts of the world, silicon battery adoption is still in the early stages. But momentum is building. 

Last year’s OnePlus 15 made headlines for its whopping 7,300-mAh battery with a silicon-carbon design. (For comparison, the Samsung Galaxy S26 Ultra has a 5,000-mAh battery, and the iPhone 17 Pro Max has roughly the same capacity.) Motorola’s first book-style foldable phone, the Razr Fold, packs a 6,000-mAh silicon-carbon battery. More phones with larger capacities could become available in the US in the coming years as the technology advances.  

Because of their purchasing habits, consumers in China and other parts of Asia are more willing to overlook the potential shortcomings of newer battery technologies, Mikolajczak notes. People who splurge on flashier gadgets and upgrade more frequently won’t be as sensitive to performance gaps. 

“In Asia, people are changing their phones the moment something new comes out, so that’s a great place to test-drive the newest technology,” she says. “You want to roll it out somewhere where the customers will forgive you if it sucks within a year.”

Chinese brands also tend to release phones in smaller batches than companies with wider global reach, like Apple and Samsung, which helps to reduce the likelihood of something going wrong and any associated blowback. And while Chinese phone-makers can use battery advancements to stand out in an ultracompetitive market, consistency and reliability tend to be more important for larger companies that don’t want to put their reputations on the line. 

“If I’m Apple and Samsung and the others, what I’ll do is I’ll say, ‘You know what, I’m going to walk before I run,'” Braun says. “The opportunities are for a big company to do this incrementally.”

Apple, Samsung and Pixel maker Google declined to comment on their battery plans. 

Bringing silicon to a global market

A handful of companies are manufacturing silicon battery materials on a global scale, including Washington-based Group 14. Its SCC55 product, used in silicon-carbon batteries, is said to enable up to 50% higher energy density than conventional lithium-ion batteries. 

The technology also “handles extreme charge-discharge cycles,” the company notes on its website, presumably to offset a key concern with silicon-carbon material. SCC55, designed as a straightforward drop-in replacement for graphite, powers phones like 2024’s Honor Magic 7 Pro

Rick Costantino, Group 14’s CTO and co-founder, says the company takes a different approach to manufacturing silicon battery material than some other suppliers. Rather than surrounding silicon with carbon — which Costantino compares to adding a magic shell to ice cream — Group 14 builds a carbon structure to house the silicon. He compares that design to a chocolate chip cookie or a sponge, in which either the chips or the pores are made of silicon. 

“When we tried that, we instantly got a much better result than we’d ever seen before,” he says. By volume, there are nearly equal parts of carbon, silicon and void, giving the silicon more space to breathe. 

Zooey Liao/CNET/Getty Images

“It ameliorates the larger expansion upon every cycle, and it helps anchor that silicon so it’s very, very stable. You have the best of both worlds: You have this high-capacity material that also is protected in that carbon scaffold.”

(Fittingly, I had to pause our interview at this point to plug in my laptop. “You need a better battery,” Costantino quipped.)

Costantino notes that, beyond pushing innovation at a more rapid pace, China is where a lot of battery manufacturers are based, as well as consumers. So naturally, there’s going to be wider adoption of silicon batteries in that part of the world. But he predicts a “worldwide expansion” soon, likely in the coming years.

Group 14 has a plant in South Korea where it manufactures silicon and carbon for its SCC55 product. It’s building two more plants in Washington that it aims to launch by the end of the year.   

Because energy-dense silicon allows for smaller batteries, it’s an especially valuable technology for thin and foldable phones, where space is at a premium.

“It’s a designer’s dream,” says Gene Berdichevsky, co-founder and CEO of California-based Sila Nanotechnologies, which owns the foundational intellectual property for modern silicon-carbon anodes. “It gives them freedom to either have longer runtime or a smaller device, which enables better design — or to add more features like AI that are power-hungry.” 

quote-2.png

As phone companies continue to load our devices with AI features, silicon anode advancements can help offset that strain. That can keep us from lugging bulky phones with massive batteries or having to recharge in the middle of the day, Berdichevsky notes. 

Sila commercialized its silicon technology in 2021 when it was integrated into the Whoop 4 fitness tracker. Smaller gadgets like wearables are easier to outfit with silicon because they require less anode material than devices with larger batteries, like phones. Less space also means an efficient battery is even more necessary. 

But Sila is scaling production at its facility in Moses Lake, Washington, to power a wider range of consumer electronics like smartphones and smartwatches as well as electric vehicles. 

Although Chinese phone-makers are leading the charge in adopting silicon battery technology in mobile devices, other major phone brands like Apple, Samsung and Google are sure to follow suit in the near term, Berdichevsky says. Maybe one day I won’t feel the need to keep my phone on Low Power Mode at Disneyland or lug around a battery pack.

“Three years from now, this technology is in billions of devices, and it’s in everyone’s pocket,” he predicts. “This is the biggest chemistry change in 35 years in rechargeable battery technology.”

The next frontier of battery technology

Other emerging battery technologies are taking shape in labs and manufacturing facilities around the world, with several aiming for large-scale rollout in the coming years. 

Solid-state batteries are generating perhaps the most buzz because they have among the highest energy densities. Their use of a solid electrolyte also makes them less flammable than traditional lithium-ion batteries. 

Zooey Liao/CNET/Getty Images

A key barrier to putting solid-state batteries in phones is the need for stack pressure; that is, keeping the layered components tightly pressed together so they work properly, since solid electrolytes don’t flow to fill gaps like liquids do. Maintaining that pressure requires extra structure, which takes up valuable space in slim, lightweight devices like phones — ultimately making them anything but slim and lightweight. 

Solid-state batteries aren’t yet widely commercialized and remain expensive and difficult to manufacture at scale. Semi-solid-state batteries, which blend elements of traditional lithium-ion and fully solid-state designs, are emerging as a stepping stone and have already appeared in some battery packs. But they don’t fully deliver the energy density or safety gains promised by true solid-state batteries.

Matt McDowell, a professor and co-director of the Georgia Tech Advanced Battery Center, says he expects solid-state batteries to play a significant role in consumer electronics over the next five to 10 years.

“The name of the game for smartphones is to pack as much energy as you can in the smallest space possible,” McDowell says.
“The way we’ve done that over the last 10 to 15 years is we’ve continually developed higher-performing materials to incorporate in lithium-ion batteries.” 

Silicon-carbon is the next step, but solid-state batteries may not be far behind.

Other future technologies could include lithium-sulfur batteries, which offer high theoretical energy density, and sodium-ion batteries, which are cheaper to produce and perform better in cold weather. 

But each comes with trade-offs. Lithium-sulfur batteries struggle with short cycle life and rapid degradation. Plus, they can take up a lot of volume. Meanwhile, sodium-ion batteries have lower energy density, making them too bulky and heavy for most portable electronics, like phones and laptops.

Further out on the horizon — likely after silicon-carbon becomes mainstream in consumer devices — lithium-metal anodes could represent the next frontier. They can significantly increase energy density because lithium itself acts as the active storage material, rather than relying on graphite or silicon-based anodes. But major safety, reliability and manufacturing challenges remain as researchers continue to explore their potential.

Many emerging smartphone battery technologies can generally be applied to electric vehicles. The increased power density of silicon-carbon batteries can translate to cars having longer range and, as with phones, faster charging. Donut Lab says it’s working to bring a solid-state battery to production vehicles, though some are skeptical of just how far along the technology is. 

quote-3.png

But because of the varying needs and use cases of EVs versus handheld consumer electronics, the specific battery designs for each could increasingly differ as the platforms evolve. Smartphone batteries will continue to prioritize thinness and weight, for instance, while EVs require much larger energy capacity and a significantly longer lifespan. 

“I’m not sure we’re going to see as much cross-fertilization from one to the other, as they specialize for their niche,” says Braun.    

Retrain how you recharge

Despite consumer demand for longer-lasting batteries, phone companies are also aware of our charging habits, says Michael Liu, director of research at the Volta Foundation, a global nonprofit that connects thousands of battery professionals and companies. Most people will plug in their phones at the end of the day, no matter what, he notes. 

“I’m not entirely convinced that if there was a battery that lasted multiple days, it would actually be a valuable draw for people,” Liu says. “Batteries match human behavior for consumer electronics.” 

In other words, old habits die hard. My colleague, CNET Senior Mobile Writer Jeff Carlson, says he typically charges his iPhone 17 Pro each night, regardless of the battery’s status, and will occasionally plug it in during the day before going out to snap photos or videos. That prevents him from getting anxious about his phone battery dying in the middle of the day, but he still carries a MagSafe-compatible power bank just in case.   

“So much of our daily activities have shifted to our phones, that having them unavailable puts us at an immediate disadvantage,” Carlson says. “We’ve conditioned ourselves to have always-on access to everything, so when the phone is dead, we’re cut off from news and conversations. We don’t want to miss out, even if we’re not actually missing out on anything.”

Zooey Liao/CNET/Getty Images

The stakes are higher if you’re using an older phone. CNET Senior Mobile Editor Mike Sorrentino is still rocking an iPhone 12 Pro Max, which usually hits 30% battery at around 4 p.m. each day. He makes sure to carry a wireless power bank so he’s not stranded with a dead phone. 

“My phone battery will run out in the middle of the day, and I’ve come to accept that,” he says. “I’m generally most concerned about being able to navigate my way home using transit. Even though I know what trains to take, my phone is critical for navigating the constantly changing detours and delays.”

I still find it tough to resist plugging in my phone at night, especially since I like starting the day with a full charge. Lately, though, I’ve been adjusting my routine, so I only charge it if the battery drops below 50%.

But on days when you’re out all day without access to outlets or chargers, it’s hard not to fully power up before heading out the door. That way, I can snap hundreds of photos and film the Disneyland parade — complete with a catchy Jonas Brothers soundtrack — and worry a little less about draining my battery.

Still, technology must always evolve. And while lithium-ion batteries get better each year, it may be time for a more significant leap. In CNET’s lab testing, the average battery life of all 35 phones we tested in 2025 was less than 1% higher than that of the phones we tested the previous year. 

“We’re talking, in a good year, maybe 1% to 2% energy density gain each time a new battery or a new phone is released,” Liu says. “We’re really reaching the limitations of this technology.”

Tips to extend your phone’s battery life

You don’t have to wait until the dawn of the next technology to stretch your phone’s battery life. Adopting certain charging and use habits can promote day-to-day and overall longevity. 

Liu recommends setting your phone’s charging limit to 80% rather than 100%. In many of today’s batteries, more heat and stress tend to build up during the final 20% of charging, so avoiding a full charge can help reduce degradation. If you’re traveling or know you’ll have a long day out, Liu says occasionally charging to 100% — or bringing a battery pack — can offer peace of mind.

“Modifying my behavior has been one of the most effective ways of getting my money’s worth,” Liu says.

On the iPhone, you can set a charging limit in Settings > Battery > Charging. On a Samsung Galaxy phone, go to Settings > Battery > Battery protection. On a Pixel phone, go to Settings > Battery > Battery health > Charging optimization.

Mikolajczak adds that fast charging can also accelerate battery wear and tear. She recommends opting for slower charging when possible to help avoid strain. Samsung Galaxy phones even have a built-in feature that lets you disable fast charging. Go to Settings > Battery > Charging settings and hit the toggle next to Fast charging or Fast wireless charging to disable those options.  

You shouldn’t expose your phone to high temperatures, whether that’s leaving it in a car on a hot day or setting it next to you on a sunny beach. Sometimes it’s unavoidable, like on a warm day at Disneyland when you’re constantly using your phone, but try to mitigate this as much as possible. Some wireless chargers can also warm up your device and accelerate battery degradation, so keep an eye out for that. 

Mikolajczak says to be mindful of how many applications you have running in the background, and to close whatever you don’t need. 

Ultimately, take a moment every now and then to acknowledge how much power is sitting in the palm of your hand, driven by a trusty lithium-ion battery — even if there’s still more innovation to come.

“People should appreciate their phones,” Mikolajczak says. “Realize what a great piece of technology you’ve got.”


Visual Designer | Zooey Liao

Art Director | Jeffrey Hazelwood

Creative Director | Viva Tung

Video Hosts | Owen Poole, Abrar Al-Heeti, Patrick Holland

Video EditorOwen Poole, Dillon Lopez

Project Manager | Danielle Ramirez

Editor | Corinne Reichert

Director of Content | Jonathan Skillings





Source link

Leave a Reply

Subscribe to Our Newsletter

Get our latest articles delivered straight to your inbox. No spam, we promise.

Recent Reviews


What is XPath in Selenium – Table of Content

What is XPath in Selenium?

Selenium is an open-source, most popular web automation testing tool that supports multiple browsers & OS. XPath in Selenium is an XML Path and a syntax useful for locating an element on a web page. Locating any element on the web page uses XML path or XPath expression. Further, XPath in Selenium is useful for navigating through the HTML structure of the web page. 

Moreover, XPath uses HTML DOM structure to find any element on a web page for both HTML and XML documents. 

The syntax for XPath In Selenium 

XPath in Selenium holds the element’s location on the web page. The basic syntax for XML Path Selenium is as follows-

Xpath=//tagname[@attribute="value"]

The meaning of each expression in the syntax is-

  • // : Choose the existing node.
  • Tagname: Particular node’s tagname.
  • @: This symbol denotes the “Select” attribute.
  • Attribute: Node’s attribute name.
  • Value: Attribute’s Value.

Become a master of Selenium by going through this HKR Selenium Training!

XML Document

The XML documents are the text files that contain XML data, including elements and other markups, in a sequential package. Further, it can include a wide variety of data such as numbers databases, numbers of a mathematical equation, etc. You can understand XML document with an example:-

 Kumar

   AK & Co.

    032456123

Here, the above code is divided into two parts- Document Prolog & Document Elements. Let us discuss them in brief.

Document Prolog

The document prolog appears at the top of the document, beforE the root document element. It includes XML and Document type declaration. 

Document Elements

These major building blocks of XML segregate the document into different sections. Each of these document sections perform a particular purpose. Moreover, you can easily segregate a document into different sections so that search engines can use it. Further, these document elements can be the containers having text and other elements combined. 

Types of XPath

  1. Absolute XPath:
  2. Relative XPath:
Absolute XPath

In Selenium, the absolute XPath is the direct path to find the element. This Xpath begins with the “/” (Slash) symbol and helps select the element from the root. The major drawback of this XPath is that if you change the path of the element or attribute, the absolute XPath will fail.

Relative XPath:

The Relative XPath in Selenium begins with the double forward slash “//” symbol and from the middle of the HTML DOM. You can search elements anywhere on the web page as it doesn’t need to write a lengthy Xpath. This XPath is mainly considered as it is not a complete path from the root element.

For example: //input[@id=‘ap_email’]

Suppose You launch Google Chrome and navigate to google.com. Then locate the search bar utilising XPath. By analysing the web element there is an input tag and attributes like class and id. Utilise the tag name and given attributes to create XPath that will locate the search bar.

If you want to Explore more about Selenium? then read our updated article – Selenium Tutorial

What-is-xpath-in-Selenium-1

Click the Elements tab and press Ctrl + F to open a search box in chromes developers tool.  Write XPath string selector and it will try to search based on that criteria. In the image given above, it has an input tag.  //input implies tagname. Use the name attribute and pass ‘q’ as its value. It provides XPath expression as shown below:

//input[@name=’q’]

XPath string

It has focused on the element that implies this specific element was located utilising XPath.

If you want to Explore more about Selenium? then read our updated article – Selenium Tutorial!

Check out our Latest Tutorial video. Register Now Selenium Online Course to Become an expert in Selenium.

                

Acquire Selenium with jenkins certification by enrolling in the HKR Selenium with jenkins Training program in Hyderabad!

Selenium Certification Training

  • Master Your Craft
  • Lifetime LMS & Faculty Access
  • 24/7 online expert support
  • Real-world & Project Based Learning

XPath Functions

Automation utilizing Selenium is unquestionably an incredible innovation which gives numerous approaches to distinguish an article or component on the website page. Be that as it may, in some cases we do deal with issues in recognizing the articles on a page that have similar credits. Some cases can be: components having similar credits and names or with more than one button with similar name and ids. It’s trying to train selenium to distinguish a specific item on a website page and it is the place where XPath functions to serve as the hero. 

Frequently asked Selenium Interview Questions and Answers !!

Types of XPath Functions

Selenium involves different functions. The three of the most broadly utilized functions are given below:

1) Basic XPath

The basic XPath expression selects nodes or a list of many nodes based on various elements or attributes such as ID, Name, ClassName, etc. It selects them from the XML documents. The syntax we can use for the basic XPath is –

Xpath=//input[@name="uid"
2.Contains()

It is a method used in XPath expression when the value of an attribute or element dynamically changes. You can easily find the elements with a partial text using the “Contains” feature in the XPath expression. Now understand this with the below example.:-

Xpath=//*[contains(@type,'sub')]

The above example denotes that the full value of the element type is submitted, but we use the partial text ‘sub’ here to find the element. Thus, in the above example, we tried to find the element by giving a partial text of the attribute “submit”. 

3) Using OR & AND

Here, we use two conditions, first or second condition, among which one condition must be “True” to execute it. This method is still applicable if any one or both conditions are “true”. It means that any conditions should be true to find the element. The expression we can use for this is-

Xpath=//*[@type="submit" or @name="btnReset"]

The above XPath expression will help determine whether a single or both conditions are ‘True’.

Similarly, in the “And” XPath expression, also we use two conditions, but both conditions should be “true” to locate the element. If any one of the conditions becomes “false”, then the expression cannot find the element. The syntax we can use for this function is-

Xpath=//input[@type="submit" and @name="btnLogin"]
4) Xpath Starts-with

The function Xpath-Starts-with() in the Xpath functions is useful to find the element whose attribute value changes in some conditions. Here the value changes with the refresh of the page or by performing dynamic actions on the webpage. In this method, the initial text of the attribute should be in parallel to locate the element whose attribute value changes interactively. 

Further, you can also find the elements whose attribute value doesn’t change or remain static. You can understand this function’s use by the following example:-

Xpath=//label[starts-with(@id,'message')]

The above syntax shows that two different elements start with the initial id “message”. Here, you can use the Xpath-starts with function to check whose attribute value changes or remains static.

Become a master of Selenium by going through this HKR Selenium Training in Delhi!

HKR Trainings Logo

Subscribe to our YouTube channel to get new updates..!

5) XPath Text() Function

In Selenium WebDriver, the function XPath Text() is a built-in function useful to locate elements based on the web element’s text. Using this function, you can find the same text element. Moreover, the elements that you locate must be in a string format.

Xpath=//td[text()='UserID']

Using the above expression having text function, you can locate the element that will show the exact match of the text.

6) XPath axes methods

This method in XPath functions is useful for finding complex or changing elements. However, we can see the following XPath axes methods which we can use:-

  1. a) Following- It is useful to select all the elements in the document of the existing node(). The expression you can use for this method is-
 Xpath=//*[@type="text"]//following::input
  1. b) Ancestor- The ancestor axes method is useful to select all the ancestor elements of the existing node, like parents, grandparents, etc. Here, the expression you can use is-
Xpath=//*[text()='Enterprise Testing']//ancestor::div
  1. c) Child- This axes method selects all the child elements in the documents’ current node. The expression you can use here is-
Xpath=//*[@id='java_technologies']//child::li
  1. d) Preceding- This method helps select the nodes that come before the existing ones. Here is the example expression:-
Xpath=//*[@type="submit"]//preceding::input

The above expression helps to identify all the input elements before the currently given nodes.

  1. e) Following-sibling- This method helps to select the following siblings of the existing node. All the siblings will be equivalent to the existing node, and the method will find the sibling next to the existing node. Moreover, the syntax you can use here for this method is-
xpath=//*[@type="submit"]//following-sibling::input
  1. f) Parent- It helps to select the parent from the existing node of the element. The following is the syntax you can use here.
Xpath=//*[@id='rt-feature']//parent::div

Many div(s) match with the parent, but if you want to focus on a specific element. For this you can use the below xpath syntax-

Xpath=//*[@id='rt-feature']//parent::div[1]
  1. g) Self- In this method, it selects the existing node where it selects itself only. That means the node here is the “self”. The expression you can use for self is-
Xpath =//*[@type="password"]//self::input
  1. h) Descendant- It helps to select the descendants of the existing element where it recognizes all the element descendants of the existing element. 
Xpath=//*[@id='rt-feature']//descendant::a

Selenium Certification Training

Weekday / Weekend Batches

Conclusion

XPath or an XML Path is used to locate any element or navigate through the HTML structure of a webpage. It is generally used for automation purposes and in cases where it is difficult to find elements using locators like name, class, ID, etc. However, it is the most important among the locators useful in Selenium to identify web elements. Also, it is a handy locator for the testers of web pages.

Thus, learning about XPath in Selenium will help you quickly identify a web element on a web page. 

Related Articles:



Source link