4
$\begingroup$

I am trying to get option data from BarChart.com with the following code:-

session = StartWebSession["Chrome"];
WebExecute[session,OpenPage" ->"https://www.barchart.com/stocks/quotes/AAPL/options"];  
WebExecute[session, "ClickElement" -> {"CSSSelector", "select.ng-pristine"}]

And I have difficulty to change the expiry date. With the above code, I can click the expiry but not being able to move to next expiry. How can I do this properly ?

$\endgroup$

1 Answer 1

3
$\begingroup$

Update

I was wrong, the element can be selected using the CSSSelector

expiration = 
 WebExecute[session, "LocateElements" -> {"CSSSelector", "select.ng-pristine"}]

The element needs to be located first. I don't think it can be done using {"CSSSelector", "select.ng-pristine"}. One way using XPath (which you can get using Chrome developer tools).

expiration = WebExecute[session,
   "LocateElements" -> 
    "XPath" -> 
     "//*[@id=\"main-content-column\"]/div/div[3]/div[1]/div/div[2]/select"] // First

Get list of possible values

WebExecute[session, "ElementText" -> expiration]

2020-01-17 2020-01-24 (w) 2020-01-31 (w) 2020-02-07 (w) 2020-02-14 (w) 2020-02-21 2020-02-28 (w) 2020-03-20 2020-04-17 2020-06-19 2020-07-17 2020-09-18 2021-01-15 2021-06-18 2021-09-17 2022-01-21 2022-06-17

Select a value

WebExecute[session, "TypeElement" -> {expiration, "2020-03-20"}]
$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.