Selenium Web-driver is a powerful framework for web test automation. There's always room for improvement. This improvement produced by leveraging the prevailing features of Selenium Web Driver. Selenium Web Element Extension Method in Automation Framework useful for selenium web driver.

 
 Web Element Extensions Method in Automation Framework
 

Cases of modifying Selenium Actions

Some Cases of modifying Selenium Actions given below. They are
 
1: Web Element Send Keys
 
It observed that on some word fields principles are pre-filled. the Selenium SendKeys action work, it does not take away the old text and add or append content material to it.
 
2: WebElement Click
 
There may be situations where Click action cannot work on any given aspect. In that case, we conclude clicking on the element with the aid of JavaScript or MouseHover click. To help make the code reusable we always create functions of reusable activities.
 
3: Logging
 
Logging is an essential activity in any framework. Logging can be Step Level or Action Level. Action Level logging is difficult to control, as required to enter log after every action. it becomes an automation script-write. To keep up the reliable logging on the platform.
 

What are Extension Methods?

 
Extension Methods existing types without creating type, recompiling or modifying the original type. An extension method particular kind of static method. they called as though case methods on the extended type. An expansion method static approach to a static class. where in fact the "this" modifier applied to the first parameter. The sort of the first parameter will be the type prolonged.
 

How exactly to Create Extension Method?

 
We create an expansion way for a WebElement type. So WebElement gave a parameter for this extension method. That method called by the Web Element using the dot operator.
 
Enter Text() instead of Send Keys()
 
This function is simple, it makes our code a little from concise. The original Selenium HANDY REMOTE CONTROL RC, SendKeys clear a wording field. Then send the mandatory word. In Selenium 2, word fields aren't cleared first unless carried out. the method EnterText(), were passing a Web Element type with 'this'. So that it called by any factor variable, in other words, a WebElement illustration.
 
Is Displayed() instead of Displayed()
 
Selenium's default behavior is to throw an exception if a factor is not found. Displayed method catches exclusion. To test the visibility of the elements without execution program.
 
Select By Text of Select Class
 
This put into action every action of Selenium in own way. It logging for the reason that or use try capture stop or anything.

Web Element Extensions Method in Automation Framework

 
Step 1: Build an Element_Extensions Class
 
1) Create a new folder and name it as Extensions.
 
2) Create a fresh C# course in the Extensions folder, name it as Element_Extensions.
 
3) Write the execution of the Component_Extensions class.

Feature and Property of Expansion Methods

  • It static method
  • This situated in a static class
  • The "this" keyword as the first parameter with a sort in.NET. which method called by a given type illustration on the client side.
  • An extension method in the same namespace as employed. import the namespace of the course by a using statement.
  • Any for the course that comes with an extension method but the course should be static.
  • If add new solutions to a sort and do not have the source code for this. The solution is to use and install extension ways of that type.
  • create expansion methods that have the same personal methods. the type extending, expansion methods called.
 
 

Save