Error using sendKeys() with Selenium WebDriver due to java.lang.CharSequence cannot be resolved. Solution for java.lang.CharSequence for java jre1.8


In Eclipse whenever we create a project automatically it will pick the latest jre installed in your system jre 1.8.0_25 which is in my case as shown below:






But in selenium webdriver when we use 'sendkeys()' method throws error java.lang.CharSequence cannot be resolved.









We can resolve this in two ways
1. Setting the Source level project should be greater then 1.5.

2. Roll back the jre 8 to jre 7 in Eclipse.

Steps for Setting the Source level of the Project to greater then 1.5
1. Select Project right click->Build Path->Configure Build Path.









2. Select the Java Compiler option as shown below:














3. Select check-box for 'Enable project specific settings". Change the value from the compliance level drop down from 1.4 to 1.7. Click on 'Ok' button.














4. Verify the program now the issue will be resolved.









Steps for roll-backing from jre 8 to jre 7

1. Select Project right click->Build Path->Configure Build Path.










2. Navigate to Libraries. Select the jre 1.8 and click on remove.Do not worry we are not removing the jre 1.8 from the system, we are removing the jre 1.8 reference from this project.










3. Click on Add Library Button->JRE System Library->Next.















4. Select Alternate JRE radio button. Click on 'Installed JREs' button. 
















5. In the installed JREs click on Add and Navigate to the directory where the jre7 is installed.















6. Select the JRE Type as 'Standard VM' and click on Next.
















7. In my case JRE7 is installed in the following location.
C:\Program Files (x86)\Java\jre7
Provide JRE Name -> jre7.0
Click on Finish button.















8. Select jre7.0 checkbox in the list of Installed JRE's. Click on Ok button.












9. Select the workspace default jre as JRE 7.0. Click on Finish button.
















10.  Verify the Java Build Path.
















11. Verify the program now the issue will be resolved.








Object Repository in Selenium - Reading And Writing Properties in Selenium

In Selenium Webdriver if we need to store the Object Properties, we can use Properties file where we can store both the Property name and Value.

Property Name : Key
Property Value : Value

Suppose if am able to find the text box in http://www.google.com using the following properties.
In the below screenshot the Property Name is 'id' and Property Value is 'gs_taif0'. So, in future if developer changes these properties, then we have to modify the Selenium WebDriver Script. Instead of that,

we can maintain this in Properties file.
Property Name : id
Property Value :  gs_taif0












Steps for Creating the Property File:
1. Open Notepad.
2. Write the following Text as shown below:













3.Copy the file 'Google.properties' in the project Folder. Suppose i create a java project with name as 'Selenium Project' then we have to copy the property file in the project folder as shown below:












Steps for Writing a Java Program to Read the property value in Selenium WebDrvier Script

Before we get into the program we need to understand the JAVA API(Application Programming Interface).

Java provides an java.util.Properties class which helps us to read the property values and update the property values.

Please find the methods below which helps us in reading and writing the property values:

1. loadReads a property list (key and element pairs) from the input byte stream.


voidload(InputStream inStream)
Reads a property list (key and element pairs) from the input byte stream.

2. setProperty: Useful for setting values for the Key.

ObjectsetProperty(String key, String value)
Calls the Hashtable method put.

3. getProperty: Searches for the property with the specified key in this property list.


StringgetProperty(String key)
Searches for the property with the specified key in this property list.

Program for Reading the Property file:


import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class ReadPropertyFile {

public static void main( String[] args ) throws IOException{

FileInputStream fis = new FileInputStream("Google.properties");
Properties prop = new Properties();
prop.load(fis);
//Reading the property values
System.out.println(prop.getProperty("search_textbox_id"));


WebDriver driver = new FirefoxDriver();
driver.get("http://www.google.com");
driver.findElement(By.id(prop.getProperty("search_textbox_id")));


}
}














The Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string.

Jenkins with Hithub

Jenkins with Hithub