How is this achieved? Here it says the java version is:
WebDriver driver; // Assigned elsewhere
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("return document.title");
But I can't find the C# code to do this.
How is this achieved? Here it says the java version is:
WebDriver driver; // Assigned elsewhere
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("return document.title");
But I can't find the C# code to do this.
The object, method, and property names in the .NET language bindings do not exactly correspond to those in the Java bindings. One of the principles of the project is that each language binding should "feel natural" to those comfortable coding in that language. In C#, the code you'd want for executing JavaScript is as follows
Note that the complete documentation of the WebDriver API for .NET can be found at this link.
You could also do:
How about a slightly simplified version of @Morten Christiansen's nice extension method idea:
or maybe the generic version:
the nuget package
Selenium.Support
already contains an extension method to help with this. Once it is included, one liner to executer scriptor
I prefer to use an extension method to get the scripts object:
Used as this: