Home > Article > Web Front-end > How Do I Execute JavaScript with Selenium WebDriver in C#?
Executing JavaScript with Selenium WebDriver in C#
The question poses an inquiry regarding the process of executing JavaScript using Selenium WebDriver in C#, specifically related to finding the corresponding C# code for executing a Java-based script.
Java Code:
<code class="java">WebDriver driver; // Assigned elsewhere JavascriptExecutor js = (JavascriptExecutor) driver; js.executeScript("return document.title");</code>
C# Equivalent:
In C#, the equivalent code is as follows:
<code class="csharp">IWebDriver driver; // Assume assigned elsewhere IJavaScriptExecutor js = (IJavaScriptExecutor)driver; string title = (string)js.ExecuteScript("return document.title");</code>
Notes:
The above is the detailed content of How Do I Execute JavaScript with Selenium WebDriver in C#?. For more information, please follow other related articles on the PHP Chinese website!