0

I have a button that I am retrieving with canopy like this...

let buttons = elements ".buttonClass"

The last button is the one I want to click, but when I do...

click buttons.tail

I get an error that says

"Can't click [OpenQA.Selenium.Remote.RemoteWebElement] because it is not a string or webelement"

So my question is, is there a way to do what I'm trying to do?

Jonathan March
  • 5,800
  • 2
  • 14
  • 16
DotNetRussell
  • 9,716
  • 10
  • 56
  • 111

2 Answers2

4

buttons.tail is not the "last button", but a list consisting of all buttons but the first one. That's what "tail" normally means in relation to lists. Try this:

let list = [1;2;3]
let tail = list.Tail   // tail = [2;3]

To get the last element of an F# list, use the List.last function:

let buttons = elements ".buttonClass"
click (List.last buttons)
Fyodor Soikin
  • 78,590
  • 9
  • 125
  • 172
0

The list that's returned with elements (selector) is an IWebElement List

So, by accessing the list with buttons.Item (buttons.Length - 1) I am able to access the WebElement object which has a click function on it.

let buttons = elements ".buttonClass"
(buttons.Item (buttons.Length - 1)).Click()

Documentation for RemoteWebElement

Canopy API Documentation

DotNetRussell
  • 9,716
  • 10
  • 56
  • 111
  • 1
    I suggest using `List.last buttons` or `buttons |> List.last`; it's a little easier to read. And easier to read, in the long run, means fewer bugs. – rmunn Feb 24 '17 at 23:59