Click a Canopy WebElement

379 views Asked by At

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?

2

There are 2 answers

1
DotNetRussell On BEST ANSWER

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

5
Fyodor Soikin On

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)

Related Questions in F#