How can I call a javascript function in a website with selenium

So this is an element in a website

<span class="log-out-ico" ng-click="logout()">/

Let’s say I don’t want to click it, instead I just want to run the "logout()" script from selenium,
Is it even possible? If so how?!

This is what I tried

IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("logout()");

But I get this error :

javascript error: logout is not defined

50 thoughts on “How can I call a javascript function in a website with selenium”

Leave a Comment