Login Register
Code2night
  • Home
  • Guest Posts
  • Blog Archive
  • Tutorial
  • Languages
    • Angular
    • C
    • c#
    • C#
    • HTML/CSS
    • Java
    • JavaScript
    • Node.js
    • Python
    • React
    • Security
    • SQL Server
    • TypeScript
  • Post Blog
  • Tools
    • JSON Beautifier
    • HTML Beautifier
    • XML Beautifier
    • CSS Beautifier
    • JS Beautifier
    • PDF Editor
    • Word Counter
    • Base64 Encode/Decode
    • Diff Checker
    • JSON to CSV
    • Password Generator
    • SEO Analyzer
  1. Home
  2. Blogpost

Can only iterate over an array or an instance of java.lang.Iterable

Date- Aug 31,2023

3784

java selenium



It looks like you're attempting to use a for-each loop to iterate over a collection of WebElement objects obtained by finding all anchor (<a>) elements using the By.tagName method in Selenium WebDriver.

However, there's a slight issue with the code. The findElement method returns a single WebElement, not a collection of elements. To find multiple elements, you should use the findElements method instead. Here's the corrected version of your code:


In this corrected code:

  1. 1. driver.findElements(By.tagName("a")) returns a list of WebElement objects representing all the anchor elements on the page.
  2. 2. The for-each loop then iterates over each element in the anchorElements list, allowing you to perform actions on each anchor element.

Remember to replace the comments inside the loop with the actual code you want to execute for each anchor element.



S
Shubham Batra
Programming author at Code2Night — sharing tutorials on ASP.NET, C#, and more.
View all posts →

Related Articles

String Joiner
Jul 13, 2023
NoSuchwindowException in Java
Aug 31, 2023
java.lang.IndexOutOfBoundsException
Aug 21, 2023
java.lang.IllegalStateException: The driver executable does not exist
Aug 21, 2023

Comments

Contents

More in Java

  • User-defined data types in java 6171 views
  • Java Type Casting 6165 views
  • How to add (import) java.util.List; in eclipse 5777 views
  • org.openqa.selenium.SessionNotCreatedException: session not … 5731 views
  • Java Program to Display Fibonacci Series 4883 views
View all Java posts →

Tags

AspNet C# programming AspNet MVC c programming AspNet Core C software development tutorial MVC memory management Paypal coding coding best practices data structures programming tutorial tutorials object oriented programming Slick Slider StripeNet
Free Download for Youtube Subscribers!

First click on Subscribe Now and then subscribe the channel and come back here.
Then Click on "Verify and Download" button for download link

Subscribe Now | 1760
Download
Support Us....!

Please Subscribe to support us

Thank you for Downloading....!

Please Subscribe to support us

Continue with Downloading
Be a Member
Join Us On Whatsapp
Code2Night

A community platform for sharing programming knowledge, tutorials, and blogs. Learn, write, and grow with developers worldwide.

Panipat, Haryana, India
info@code2night.com
Quick Links
  • Home
  • Blog Archive
  • Tutorials
  • About Us
  • Contact
  • Privacy Policy
  • Terms & Conditions
  • Guest Posts
  • SEO Analyzer
Free Dev Tools
  • JSON Beautifier
  • HTML Beautifier
  • CSS Beautifier
  • JS Beautifier
  • Password Generator
  • QR Code Generator
  • Hash Generator
  • Diff Checker
  • Base64 Encode/Decode
  • Word Counter
  • SEO Analyzer
By Language
  • Angular
  • C
  • c#
  • C#
  • HTML/CSS
  • Java
  • JavaScript
  • Node.js
  • Python
  • React
  • Security
  • SQL Server
  • TypeScript
© 2026 Code2Night. All Rights Reserved.
Made with for developers  |  Privacy  ·  Terms
Translate Page