Select From a Combo/Drop Down Box

Following the loss of Yahoo API for downloading data I am trying to write a script that will down load historical prices and dividends. I have managed to get it working with prices but cannot work out how to get the dividend information.

The script that follows is truncated in that it just goes through the steps without downloading any data. If you run the script it ends at a drop down box (or combo) that has 3 options “Historical”, “dividends” & “Stock Splits”. I have added a note to show here I need to access or select the “Dividend” option and then I would apply the selection.

Any thoughts greatly appreciated .

Mitch

tell application "System Events"
	tell process "Safari"
		--Open to Yahoo finance
		tell application "Safari"
			tell window 1
				set current tab to (make new tab with properties {URL:"https://finance.yahoo.com"})
			end tell
		end tell
		delay 4
		--For purpose of this have set Stock symbol to GE
		set value of text field 1 of group 1 of group 1 of group 2 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1 to "GE"
		delay 5
		--Search for Data for Stock Symbol in box GE for this test
		click button 1 of group 2 of group 1 of group 2 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1
		--Click on Historical Data
		delay 5
		click static text 1 of UI element 1 of group 9 of group 1 of group 8 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1
		delay 5
		--Drop down date Field
		click text field 1 of group 1 of group 2 of group 9 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1
		display dialog "Drop Down Box for Date Visible"
		--Select last 5 years data
		display dialog "Now Select option for 5 Years"
		click static text 1 of group 7 of group 1 of group 2 of group 9 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1
		--Click on the Done Button	
		click button 1 of group 1 of group 2 of group 9 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1
		display dialog "Done button Clicked"
		--Drop down Show field "Historical" "dividends Only" & "Stock Splits" 
		display dialog "Now Click Historical Prices"
		
		--This opens the drop down/combo box
		click static text 1 of group 1 of group 2 of group 2 of group 9 of UI element 1 of scroll area 1 of group 1 of group 1 of tab group 1 of splitter group 1 of window 1
		--This is where I want to select Dividends Only" by clicking or selecting and  then using key code 36 for return
	end tell
	
end tell

First thought - if Yahoo discontinued their API for Yahoo finance, switch to someone else’s API for downloading the data?

https://www.google.com/search?ei=xpB5W5juDZK0gge9j6OQCQ&q=yahoo+finance+API+replacement

Thanks for that suggestion I have now got my script working in part. Not using the API but just the correct URL thread should have thought of that before. Anyway I still have minor problem don’t know if I should post this as a new issue but as you tooth trouble to reply thought I would ask.

If I run the AppleScript from the scrip itself it works and downloads the two files I need. However if I try and run it forma button on an Excel workbook sheet. It goes as far as opening the first correct web page but does not download the data.

This is the calling routine in VBA

Sub YahooHistorical() 'Calls a scipt that allows for Historical Prices & Dividends to be downloaded from Yahoo
On Error Resume Next
MacScript (“run script(”“macintosh HD:Library:Scripts:Peter’s Scripts:Yahoo get Historical Price & Dividend V4.scpt”" as alias)")
End Sub

Thanks again

I don’t know why it would work from Script Editor but not from Excel.

Will Excel run an Applescript saved as an application? You could try saving it as an application and running it, and see if that’s any different.

Also, I meant to mention this thread from a few days before yours with someone else also scripting Yahoo Finance data retrieval post-API.

https://www.macscripter.net/viewtopic.php?id=46335