Comparing Selenium Syntax in C# and Ruby
Clearly, Ruby Wins.
Apress will release my upcoming book, titled ‘Selenium WebDriver Recipes in C#, 3rd edition,’ in the coming months.
When I started learning programming, my father told me to be open-minded when comes to programming languages. He always encouraged me to try new ones. Before the opportunity to write this Selenium C# book, I hadn’t used C# before. Not a big deal, I just learnt it as I went. (I use Java at work, and prefer Ruby for scripting purposes)
This article provides a brief comparison of Selenium syntax in both C# and Ruby.
1. Some common operations in C# is long and complex
Taking waiting a fixed time (commonly used) for example,
System.Threading.Thread.Sleep(500); // C#
sleep(0.5) # Ruby
2. C# needs to type extra ()
for some statements
In Visual Studio, the auto-complete sometimes is not right.
In this case, driver.Navigate.GoToUrl
is wrong syntax. The correct one is driver.Navigate().GoToUrl(...)
. But Navigate()
takes no arguments, i.e., an extra set of parantheses ()
is needed to match the syntax.