Java Tutorials for Selenium

Use of Strings in Selenium WebDriver Examples

In java Strings are special and very interesting topic and are most commonly used. String is nothing but sequence of characters such as "hello", Strings should be enclosed with double quotes(" ").

String is not a primitive type like int or float. Instead string is a class which is present in java.lang package which creates string objects.

Declaration and initialization of String is same as primitive types such as int or double but String first letter is always capital as it is a class but not keyword like int and 's' is not primitive type, rather it is reference type

Understanding Access modifiers in java

There are way too many tutorials available out there on Java Access Modifiers, here we will try to relate these access specifiers with selenium webdriver and better understand with examples using Java and selenium webdriver.

We need access modifiers in order to set/control the accessibility of classes, methods and variables. Not all modifiers applicable for all, some are applicable for classes, some are for methods, variables and some for both.

Exception Handling in Java selenium webdriver

When you start working with Selenium webdriver, you will come across different exceptions based on the code you write, the same code some times work properly and sometimes it will not. You will see some or the other exception when you execute your scripts. When ever you see these exception regularly you will get frustrated.

When ever we develop any scripts, we will try give the best quality code that works fine. But Unfortunately, sometimes exceptions come as side effects to the scripts that we develop and fails.

Break, Continue and return statements Example in Selenium webdriver

Branching statements will transfer the control from one statement to another statement. the following are branching statements in java programming
1. break
2. continue
3. return

1. break:

break statement is used to stop the execution and comes out of loop. Mostly break statement is used in switch in order to stop fall through and in loops also we use break.


While, Do..While and For loop examples

Just like decision making statements, looping statements also execute the statements based on some condition but if we want to execute the same statement more than once with condition checking then we go for looping statements.

The following are the types of looping statements in Java: -

1. while loop
2. do..while loop
3. for loop

1. while loop:

while loop is the basic of all looping statements, which executes the loop repeatedly until the conditional expression evaluates to false.


Switch Case example in Java Selenium

It is also one type of Conditional Statements, which is basically used to write for menu driven programs. When ever there are more number of options to select then we will go for Switch statement i.e., single expression with many possible options. The same thing can be done using if..else statements but it can get very confusing and if..else statement is difficult to change when it becomes highly nested.


If, If Else and Nested If examples with Selenium

Control Flow Statements:

Control flow statements, controls the normal flow of execution and executes based on conditions specified by the developer.

There are three types of Control Flow Statements :
Decision Making Statements (Selection Statements)
Looping Statements (Iterative Statements)
Branching Statements (Transfer Statements)