seleniumWebdriver
seleniumWebdriver

Reputation: 11

java.lang.IllegalArgumentException: Cannot find elements when the XPath expression is null

I'm testing with the selenium webdriver, and getting an error. I have set the Ro.properties file and put all locator in properties file.

Below is the code that I am using, can anyone please help me out?

public class usePropertiesFile {
    private WebDriver driver;
    public static Properties prop = new Properties();
    public static FileInputStream fip = null;
    @BeforeTest
    public void setup() throws IOException {
        driver =new FirefoxDriver();
        driver.get("http://gmail.com/");
        driver.manage().window().maximize();

    }
    @AfterTest
    public void Teardown() {
        driver.quit();
    }
    @Test
    public void testPropFile() throws Exception {
              fip = new FileInputStream("C:\\Users\\src\\config\\RO.properties");
        prop.load(fip);
        driver.findElement(By.xpath(prop.getProperty("login_use"))).clear();
        driver.findElement(By.xpath(prop.getProperty("login_use"))).sendKeys("userid");
    }
}

Upvotes: 1

Views: 10099

Answers (2)

Umamaheshwar Thota
Umamaheshwar Thota

Reputation: 521

I think you are getting the Illegal Argument error because your Ro.Properties file is not present the path you have declared in the script.

First of all, copy the updated Ro.properties file in the execution folder path (if it is not present). Then verify the attributes used properly assigned or not.

Execute the script, it should work.

Upvotes: 1

acdcjunior
acdcjunior

Reputation: 135862

On your .properties file (located at C:\Users\src\config\RO.properties), the property login_use is not set.

In other words, you test program is finding the properties file (otherwise it'd throw a file not found exception), but is not finding a property with login_use name.

Try adding after prop.load(fip);:

System.out.println("Value of 'login_use': "+prop.getProperty("login_use"));

It will probably print null.

Add this line to your RO.properties:

login_use=//input[@name\='Email']

It should now get //input[@name\='Email'] (instead of null) as value (change the expression to what you want, of course).

Upvotes: 1

Related Questions