Cannot catch NoSuchElementException with Selenide - selenide

I’m trying to catch NoSuchElementException. This is my code:
public void checkActiveApps() {
try {
$(BUTTON).click();
} catch (org.openqa.selenium.NoSuchElementException e) {
System.out.println(e);
}
}
But the exception is still thrown. How to catch it?
This is the log:
Element not found {button[role='checkbox']}
Expected: visible
Screenshot: file:/Users/user/source/project/build/reports/tests/1537866631954.0.png
Page source: file:/Users/user/source/project/build/reports/tests/1537866631954.0.html
Timeout: 4 s.
Caused by: NoSuchElementException: Unable to locate element: button[role='checkbox']
at com.codeborne.selenide.impl.WebElementSource.createElementNotFoundError(WebElementSource.java:31)
at com.codeborne.selenide.impl.ElementFinder.createElementNotFoundError(ElementFinder.java:82)
at com.codeborne.selenide.impl.WebElementSource.checkCondition(WebElementSource.java:59)
at com.codeborne.selenide.impl.WebElementSource.findAndAssertElementIsVisible(WebElementSource.java:72)
at com.codeborne.selenide.commands.Click.execute(Click.java:16)
at com.codeborne.selenide.commands.Click.execute(Click.java:12)
at com.codeborne.selenide.commands.Commands.execute(Commands.java:144)
at com.codeborne.selenide.impl.SelenideElementProxy.dispatchAndRetry(SelenideElementProxy.java:90)
at com.codeborne.selenide.impl.SelenideElementProxy.invoke(SelenideElementProxy.java:65)
I use selenide version 4.12.3

Selenide does not throw Selenium exceptions as it uses it's own.
You can try using:
public void checkActiveApps() {
try {
$(BUTTON).click();
} catch (com.codeborne.selenide.ex.ElementNotFound e) {
System.out.println(e);
}
}
Why do you want to catch it anyway?

Related

Expecting to catch an Aggregate Exception

I am trying to understand exception handling in TPL Dataflow so I can effectively handle errors. In my comment numbered 1. below I am expecting to catch an AggregateException but everything just halts and doesn't recover. If I remove the throw (2.) then the ActionBlock continues to process but again, the AggregateException handler doesn't trigger.
Would anyone be able to help with an explanation to improve my intuition.
Would also welcome any documentation references on the topic.
async Task Main()
{
var ab = new System.Threading.Tasks.Dataflow.ActionBlock<int>(async a => {
try
{
await Task.Delay(100);
if (a == 7)
{
throw new Exception("Failed");
}
else
{
Console.WriteLine(a);
}
}
catch (Exception ie)
{
Console.WriteLine(ie.Message);
throw; //2. This causes the actionblock to halt, removing allows block to continue
}
});
for (int i = 0; i < 10; i++)
{
await ab.SendAsync(i);
}
ab.Complete();
try
{
await ab.Completion;
}
catch (AggregateException ae)
{
Console.WriteLine(ae.Flatten().Message);
// 1. Expecting to catch here.
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
What you're seeing is the await unwrapping your Aggregate Exception. When you await the completion task the exception is unwrapped and thrown to the general exception catch. But if you don't unwrap the exception then you'd see the exception caught as an aggregate exception like this:
try
{
ab.Completion.Wait();
}
catch (AggregateException ae)
{
Console.WriteLine("Aggregate Exception");
// 1. Expecting to catch here.
}
catch (Exception e)
{
Console.WriteLine("Exception Caught");
}
It's obviously better to properly await the completion but this samples shows you that indeed an AggregateExcpetion is caught when it's not unwrapped.

system.threading .threadAbortException error

I am taking over an existing website and I am trying to get the application running on my machine, however I can't launch the application because I get the following error.
System.Threading.ThreadAbortException occurred
HResult=0x80131530
Message=Thread was being aborted.
Source=mscorlib
StackTrace:
at System.Threading.Thread.AbortInternal()
at System.Threading.Thread.Abort(Object stateInfo)
This is my code
protected void Application_BeginRequest(object sender, EventArgs e) {
if (DemoWeb.Helpers.Application.ApplicationManager.StartUpError != "")
{
Response.Write("<div class=\"demoweb-securityerror\">" + demoweb.Helpers.Application.ApplicationManager.StartUpError + "</div>");
Response.End();
}
How can I get it to bypass the response.end?
I got it to work.
I just added a try and catch method and moved the Response.End
try {
// code
}
catch(exception ex)
{
Response.End();
}

Java 8 Path Stream and FileSystemException (Too many open files)

geniuses!
I'm practicing Java 8.
So if I do something like this:
Files.walk(Paths.get(corpusPathStr))
.filter(path -> path.toFile().isFile())
.forEach(path -> {
try {
Files.lines(path)
.forEach(...);
} catch (IOException e) {
e.printStackTrace();
}
});
I got FileSystemException error.
If I open a file under forEach, may too many files be opened?
Or are there other reasons causing FileSystemException (Too many open files)?
Thanks for your help in advance!
Use
try(Stream<Path> stream = Files.walk(Paths.get(corpusPathStr))) {
stream.filter(path -> Files.isRegularFile(path) && Files.isReadable(path))
.flatMap(path -> {
try { return Files.lines(path); }
catch (IOException e) { throw new UncheckedIOException(e); }
})
.forEach(...);
}
catch(UncheckedIOException ex) {
throw ex.getCause();
}
The streams returned by Files.walk and Files.lines must be properly closed to release the resources, which you do by either, a try(…) construct or returning them in the mapping function of a flatMap operation.
Don’t use nested forEachs.
The UncheckedIOException might not only be thrown by our mapping function, but also the stream implementations. Translating it back to an IOException allows to treat them all equally.
Files::line opens and reads the file in a lazy manner, i.e. Stream<String>. Since you're not closing any of your opened Streams you're getting such an error.
So when you're done reading a file you should close its handle. Since the returned Stream is AutoCloseable you can and should use a try-with-resource block.
try (Stream<Path> walk = Files.walk(Paths.get(""))) {
walk.filter(Files::isRegularFile).forEach(path -> {
try (Stream<String> lines = Files.lines(path)) {
lines.forEach(System.out::println);
} catch (IOException e) {
e.printStackTrace();
}
});
} catch (IOException e) {
e.printStackTrace();
}

SSIS Script Task is throwing an exception, how to view the message?

SSIS is showing some useless "Target of invocation has thrown an error" along with an equally useless stack trace that shows only the invocation call. Logging is enabled.
Is there a way to view the actual exception message thrown by the package without attaching some debugger?
Just trap the exception in a try..catch statement and use the FireError method in the catch block:
public void Main()
{
...
try
{
...
Dts.TaskResult = (int)ScriptResults.Success;
}
catch (Exception ex)
{
Dts.Events.FireError(0, "ERROR", ex.Message, null, 0);
Dts.TaskResult = (int)ScriptResults.Failure;
}
}

Migrate from Javafx2.2 to Javafx8

I am trying to migrate Javafx2.2 application to Javafx8. I am getting following issue while using nested FXML:
javafx.fxml.LoadException: Root hasn't been set.
Use method setRoot() before load.
FXML file:
<fx:root type="javafx.scene.layout.VBox"
xmlns:fx="http://javafx.com/fxml"
xmlns="http://javafx.com/javafx/8"
fx:controller="com.ui.TestController">
<TextField fx:id="textField"/>
<Button text="Click Me"/>
</fx:root>
Code:
FXMLLoader loader = new FXMLLoader();
loader.setResources(bundle);
InputStream in = Main.class.getClassLoader().getResourceAsStream(fxml);
loader.setBuilderFactory(new JavaFXBuilderFactory());
loader.setLocation(Main.class.getResource(fxml));
Node page = null;
try {
page = (Node) loader.load(in);
} catch (IOException e) {
logger.error("{}", e);
} finally {
try {
in.close();
} catch (IOException e) {
logger.error("{}", e);
}
}
I need page node to set in another BorderPane.center. It works with Javafx2.2. What I am missing here? Any help would be appreciated.
Using <VBox></VBox> instead of <fx:root type="javafx.scene.layout.VBox"></fx:root> has fixed this issue, atleast for Javafx build b121.

Resources