Tag: nosuchelementexception

断言网页中缺少元素,给出NoSuchElementException

需要声明网页中没有这样的元素,当尝试使用fieldValueBox.isDisplayed(); 而不是“假”它抛出“NoSuchElementFound”exception。 现在我正在使用’try catch’并在’catch’中做出决定

扫描程序 – java.util.NoSuchElementException

有没有人看到这个问题? 第一个输入工作正常,但在第一个循环后,它不会要求再次输入值。 我该如何解决? int value; while(true) { Scanner scan = new Scanner(System.in); System.out.println(“Enter a value”); try { value = scan.nextInt(); System.out.println(“value provided is: ” + value); scan.nextLine(); // consumes “\n” character in buffer } catch(InputMismatchException e) // outputs error message if value provided is not an integer { System.out.println(“Incorrect input type. Try again.”); continue; // […]

调用.next()方法时扫描程序NoSuchElementException

在Java中,我得到了这个例外: Exception in thread “main” java.util.NoSuchElementException at java.util.Scanner.throwFor(Unknown Source) at java.util.Scanner.next(Unknown Source) at com.reading.text.Activity3.readFile(Activity3.java:22) at com.reading.text.Activity3.main(Activity3.java:10) 从这个Java代码: public static void main(String args[]) { readFile(“C:/Users/forsakendoll/Desktop/boom.txt”); } public static void readFile(String path) { Scanner file = null; try { file = new Scanner(new File (path)); } catch (FileNotFoundException e) { e.printStackTrace(); } finally { while (file.hasNext()) { […]

java.util.NoSuchElementException在java中使用iterator

我正在尝试使用迭代器在我的Logs列表中遍历列表。 目标是搜索包含与新日志相同的电话号码,类型和日期的日志 但是,我在条件语句中得到了java.util.NoSuchElementException。 有谁知道可能导致问题的原因? 我的代码 public void addLog(String phonenumber, String type, long date, int incoming, int outgoing) { //Check if log exists or else create it. Log newLog = new Log(phonenumber, type, date, incoming, outgoing); //Log exists Boolean notExist = false; //Iterator loop Iterator iterator = logs.iterator(); while (iterator.hasNext()) { //This is where get the […]

LinkedList:Collections.max()抛出NoSuchElementException

我不是通过扫描仪或其他方法迭代LinkedList ,我使用Collections.max()从LinkedList获取最大数量。 我已经在Stack Overflow上读到由于迭代器或扫描器或标记器而引发此exception,但我没有使用它们。 import java.io.*; import java.util.*; class TLG { public static void main(String[] args)throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); LinkedList first = new LinkedList(); LinkedList second = new LinkedList(); int cases = Integer.parseInt(br.readLine()); for(int i=1;i 0){ first.add(diff); } else { second.add(java.lang.Math.abs(diff)); } } Integer max1 = Collections.max(first); // Getting Exception […]

在Selenium中避免NoSuchElementException的最佳方法是什么?

我在Selenium WebDriver中使用Java编写了一些测试用例,并在网格(集线器和多个节点)上执行它们。 我注意到一些测试用例由于NoSuchElementException而失败。 什么是避免NoSuchElementException并确保始终找到元素的最佳和最强大的方法?