Getting the return value of Javascript code in Selenium (C#)

Getting the return value of Javascript code in Selenium (C#)

In order to return values from Javascript code, you need to execute your chosen Javascript code using the IJavascriptExecutor class. The following script does exactly this by returning the page's title as an object which is then assigned to the title variable.

var title = js.ExecuteScript("return document.title");

Leave a reply

Your email address will not be published. Required fields are marked*

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.