Questions tagged [nosuchelementexception]

Use this tag if your problem is caused by or primarily involves a NoSuchElementException in Java.

The NoSuchElementException is a RuntimeException thrown by the nextElement method of an Enumeration to indicate that there are no more elements in the enumeration.

It is also thrown by:

  • the various next* methods (nextInt, nextFloat, nextLine,...) of the Scanner class when input is exhausted;
  • the get method of the Java 8 Optional class when a value is not present;
  • the methods firstElement and lastElement in the Vector class when there are no elements;
  • the methods firstKey and lastKey in the TreeMap class when there are no keys;
  • the methods getFirst, getLast, removeFirst and removeLast in LinkedList when there are no elements;

and other collections.

573 questions
-1
votes
3 answers

Java scanner input loop throwing No Such Element exception after first loop

I want a program that repeatedly prompts the user to input a number and then prints whether that number is prime or not. This works once, then on the next iteration it gives a No Such Element Exception before the user can enter another input. I've…
-1
votes
1 answer

Can't find an element on a frame Selenium Python

I'm trying to make a bot that logs into my account. After inserting password and username I make the bot clicking on the "I'm not a robot recaptcha" using this code and it works: def _delay(): time.sleep(randint(1,3)) frames =…
neto
  • 19
  • 6
-1
votes
1 answer

I can't find the button via Selenium Java

I've tried to find it through cssSelector and xPath but displays NoSuchElementException anyway WebElement element = driver.findElement(By.cssSelector("button[class='btn btn-primary c-schedule-story-button ']")); element.click(); Screenshot is here
Noob
  • 31
  • 3
-1
votes
3 answers

How to find the element with the given xpath using Selenium and Java

public void addCustInfo() throws InterruptedException { WebDriver driver; WebDriverManager.chromedriver().setup(); driver = new ChromeDriver(); driver.get("http://www.way2automation.com/angularjs-protractor/banking/#/manager"); …
-1
votes
1 answer

Why am I getting a "Exception in thread "main" java.util.NoSuchElementException" error on a online coding class code checker?

Every time I run the code on BlueJ, Vscode, and/or Atom it works perfectly fine. However it never works on the code checker. import java.util.Scanner; import java.lang.Math; class Lesson_20_Activity { public static void main(String[]…
George Li
  • 1
  • 1
-1
votes
1 answer

JAVA.UTIL.NoSuchElementException ERROR (SITUATION BASED)

I am having trouble with this program: The history teacher at your school needs help grading a True/False test. The students’ IDs and test answers are stored in a file. The first entry in the file contains the answers to the test in the…
-1
votes
1 answer

How to send the login credentials using HtmlUnitDriver and Selenium Java

I'm tring to send the login credentials within the username and password field https://www.vignanits.ac.in/server/moodle/login/index.php which needed to be automated using HtmlUnitDriver but facing NoSuchElementException. Code trials: package…
-1
votes
2 answers

Why my Java program works perfectly in windows but it's a disaster in linux?

I wrote a program that reads a text file, deletes the requested string and rewrites it without the string. This program takes three arguments from the terminal: 1) the input file 2) the string 3) the output file. import java.io.File; import…
-1
votes
1 answer

try/except not catching NoSuchElementException in loop of Xpath which uses increment of row

Many thanks. I am using % format to increment row number inside a for loop to click() on the rows to open new tab, scrape data, close new tab and click on next row. The code runs well until it hits a row that is not a clicklable element. The…
A Dean
  • 1
  • 1
  • 3
-1
votes
1 answer

Scanner noSuchElementException. What is the cause of it? How can i fix it?

Scanner newName = new Scanner(System.in); //creating scanner object System.out.println("Δωστε ονομα : "); String getOnoma = newName.nextLine(); /*throws no such element exception at String…
-1
votes
1 answer

Method of abstract clas found cannot be found in build jar

I have a maven project where a class inherits from an abstract class. When i run the project in eclipse, everything is fine, no problems when i call inherited methods of the implementation. After building the jar with the maven goal 'clean…
-1
votes
1 answer

Why do I have this java.util.NoSuchElementException?

If I call a class member using Scanner, and if I had used Scanner before in the main method, I get the NoSuchElementException error even though all the inputs are available. import java.util.Scanner; import java.io.*; class Reminder{ static…
-1
votes
2 answers

Return 'NameError' instead of 'Pass' when Can't find element

I am using Python Selenium. When I try this: try: element = driver.find_element_by_xpath('--path--').text.encode('ascii','ignore') except NoSuchElementException: pass print element But, when element does not exist, shown error NameError:…
silver_river
  • 169
  • 1
  • 10
-1
votes
1 answer

Getting NoSuchElementException using Scanner class

I am getting the infamous NoSuchElementException when reading from a "|" delimited text file using the scanner class. I am taking the values of each token and assigning them to values within a separate class using setter methods. I can't seem to…
-1
votes
1 answer

Exception in thread "main" java.util.NoSuchElementException: No line found 3

In this code, throws me this exception: Exception in thread "main" java.util.NoSuchElementException: No line found at java.util.Scanner.nextLine(Scanner.java:1540) at…