I am a newbie to F# Canopy and am testing out inputting a date into input boxes at https://www.treasurydirect.gov/GA-FI/FedInvest/selectSecurityPriceDate.htm. When running the Canopy code below, I receive a "user-unhandled" exception stating "canopy.types.ConaopyElementNotFoundException: 'can't find element id=priceDate.month'" although the element can be seen with the page source as well as the Selenium Page Object Generator and Selenium Object Finder extensions for Chrome. It seems that for some page objects, Canopy doesn't pick up on those elements... or I am missing something. Any thoughts?
open System
open canopy
open canopy.runner.classic
open canopy.configuration
open canopy.classic
[<EntryPoint>]
let main argv =
canopy.configuration.chromeDir <- System.AppContext.BaseDirectory
//start an instance of chrome
start chrome
"testing UST prices" &&& fun _ ->
//this is an F# function body, it's whitespace enforced
//go to url
url "https://www.treasurydirect.gov/GA-FI/FedInvest/selectSecurityPriceDate.htm"
click "id=priceDate.month"
"id=priceDate.month" << "3"
click "id=priceDate.day"
"id=priceDate.day" << "31"
click "id=priceDate.year"
"id=PriceDate.year" << "2020"
click "Show Prices"
click "CSV Format"
//run all tests
run()
printfn "press [enter] to exit"
System.Console.ReadLine() |> ignore
quit()
0
Looks like you are writing the XPath wrong.
This will work
click "//*[#id='priceDate.month']"
"//*[#id='priceDate.month']" << "3"
click "//*[#id='priceDate.day']"
"//*[#id='priceDate.day']" << "31"
click "//*[#id='priceDate.year']"
"//*[#id='priceDate.year']" << "2020"
A solution to find the correct XPath is by using developer tool in Chrome.
Right click the element and Copy -> Copy XPath
Selenium (and consequently canopy) support CSS
click "#elemId"
and XPath
click "//*[#id='elemId']"
selectors.
Related
Output display user input integer, instead of Even or Odd
import 'dart:io';
void main() {
print('Enter your number: ');
int n = int.parse(stdin.readLineSync()!);
var result = n % 2 == 0 ? "Even" : "Odd";
print('Your number is : $result');
}
The problem is that your program is running inside the "Debug Console" in VS Code. The following explanation can be found in the Dart settings in VS Code:
The Debug Console has more functionality because the process is controlled by the debug adapter, but is unable to accept input from the user via stdin.
You can change this by going into File -> Preferences -> Settings. Here you go into Extensions -> Dart & Flutter. If you scroll down you can find "Dart: Cli Console". You can also just search for "Dart Cli console":
Instead of "debugConsole" set this to "terminal". Try start your program again and it should now be running inside the "Terminal" tab instead and you should be able to interact with your program and provide data to it though keyboard inputs.
I am learning vala (after a couple years of Java) and I have this very simple code, just to make a few tests :
button_2.clicked.connect (() => {
string test = "hello";
stdout.printf (test);
});
It is a Gtk.Window class, and when I run it and click the button, say five times, nothing happens.
Then, when I close the window, all five print outputs appear together in the terminal.
hellohellohellohellohello
In a Java application, after each click of a button, the output individually shows in the terminal.
I wonder why a Vala app doesn't print while the window is open, and if there is a way around it.
Output is being buffered. Insert a newline, or call stdout.flush().
Exploring F# with FSharp.Charting I thought I would start with a simple 'hello world' but it leaves me with more questions then lines of code.
#load #"..\packages\FSharp.Charting.0.90.14\FSharp.Charting.fsx"
open FSharp.Charting
let chart = Chart.Line([ for x in 0 .. 10 -> x, x*x ])
chart.ShowChart()
chart.SaveChartAs(#"C:\Temp\chart.png",ChartTypes.ChartImageFormat.Png)
This works in interactive window in VS, but what I want to do is execute this script from the cmd line (using fsi.exe). I made an association with fsx files to fsi, but when I execute it it opens fsi but no chart is created. What do I need to do?
Short answer: add the following line at the end of your program:
System.Windows.Forms.Application.Run()
Long answer:
The chart does get created, but it immediately disappears, because your program immediately exits, right after creating the chart. This does not happen in the F# Interactive window in Visual Studio, because the F# interactive window doesn't close immediately after executing your program - it just hangs out there, waiting for you to submit more code for execution.
In order to make your program not exit immediately, you could implement some waiting mechanism, such as waiting for a set amount of time (see System.Threading.Thread.Sleep) or waiting for the user to press Enter (via stdin.ReadLine()), etc.
However, this won't actually help you, because there is the next problem: the chart is drawn via Windows Forms, which relies on the message loop running - otherwise the window can't receive messages, and so can't event paint itself.
FSI does have its own built-in event loop, and this is how your program works under VS. However, if you implement a "waiting" mechanism (e.g. stdin.ReadLine()), this event loop will be blocked - won't be able to pump messages. Therefore, the only sane way to keep your program from exiting, while not interfering with the functioning of the chart window, is to start your own event loop. And this is exactly what Application.Run() does.
Saving to disk without displaying:
(in response to comment)
From what I understand, the FSharp.Charting library was intended as a quick-and-dirty way to display charts on the screen, primary use case being exploring datasets live within F# Interactive. More specifically, some key properties of the Chart object, such as ChartAreas and Series are not initialized upon chart creation, but only when it is shown on the screen (see source code), and without these properties the chart remains empty.
Short of submitting a pull request to the library, I recommend dropping down to the underlying System.Windows.Forms.DataVisualization.Charting.Chart:
open System.Windows.Forms.DataVisualization.Charting
let ch = new Chart()
ch.ChartAreas.Add( new ChartArea() )
let s = new Series( ChartType = SeriesChartType.Line )
s.Points.DataBind( [for x in 1..10 -> x, x*x], "Item1", "Item2", "" )
ch.Series.Add s;
ch.SaveImage(#"C:\Temp\chart.png", System.Drawing.Imaging.ImageFormat.Png)
I try to play with fsharp under Ubuntu (and yes, I slowly figure out that it is more pain than fun), I already installed Mono, VSCode and Ionide extension and I can create and build F# projects. Unfortunately when I run simple F# script via F# Interactive:
printfn "bar"
In terminal window I get:
>
- printfn "bar"
-
- ;;
bar
val it : unit = () F# 4.0 (Open Source Edition)
> ^?^?414;3R^?^?^?^?^?^? the Apache 2.0 Open Source License
The strange sequence ^?^? looks like unrecognized terminal escape codes, but when I use bash from within VSCode there is nothing like this.
What's more the strange sequence reappears after every command executed in FSI:
> let j = 9;;
val j : int = 9
> printfn "foo";;
foo
val it : unit = ()
> ^?^?
Does anyone have the same problem and knows a solution (or maybe just knows a solution)?
EDIT: Problem occurs mostly when I execute commands via Ionide Alt+Enter shortcut
This looks like the https://github.com/Microsoft/vscode/issues/19766 bug. VS Code 1.9 introduced a new setting, terminal.integrated.flowControl, that defaults to true. The ^? characters you're seeing (and any ^S and ^Q characters that might show up) come from this "flow control" feature, which doesn't play well with F# Interactive. Change your VS Code settings to set terminal.integrated.flowControl to false and your problem should go away.
A total noob in Applescript, please bear with me…
We have a process where we use System Events to control the Print dialog in Acrobat X. This works fine; we can "click" the Print button.
Now, we have to wait until the document is printed. While the document prints, a dialog opens, with title "Print", a progress bar and a Cancel button. We can only continue when this window closes.
So far, I have not been successful with that wait; the Applescript continues and that messes up the process.
What I have currently is (note this is part of a bigger script, and variables are defined and appear to be valid.
We have Acrobat active, and the Print dialog is open:
tell application "System Events"
tell process "Acrobat"
-- now we set all the options in the Print dialog,
-- which is in the window Print
click button "OK" of window "Print
end tell
end tell
delay 5
-- this gives Acrobat time to get printing and to open that print dialog window
repeat while exists window "Print"
delay 1
end repeat
close active doc saving no
I also tried to put that code in a Timeout, but no chance.
Now, I am stuck, but I am sure it is a stupid beginner's error.
Another note: I was not able to get the name of this "Print" window using UIElementInspector.
Thanks a lot in advance for any advice.
Is your code enclosed in some tell application block that you haven't reported here?
It should work if you move the repeat loop into the tell process block:
tell application "System Events"
tell process "Acrobat"
-- now we set all the options in the Print dialog,
-- which is in the window Print
click button "OK" of window "Print"
delay 5
-- this gives Acrobat time to get printing and to open that print dialog window
repeat while exists window "Print"
delay 1
end repeat
end tell
end tell
close active doc saving no