Reputation: 25
The relative path to an image file is shown as below in the testng.xml
.
<parameter name="adverImage" value="./res/sale_sign.jpg"/>
And the file is located in the following res folder with the following folder structure
I get the following error message on the console when the project is run.
org.openqa.selenium.InvalidArgumentException: File not found: ./res/sale_sign.jpg
Also, the same code works fine when I specify the absolute path.
-- Edit --
I'm using the following method to select the file.
private void selectImage(String image){
imageSelect.clear();
imageSelect.sendKeys(image);
}
It will be of great help if you can help me with this
Upvotes: 2
Views: 1593
Reputation: 3329
If you are trying to pass the complete path of your image, then First need to get directory path (project path).
Use this method for same :
String projectpath = System.getProperty("user.dir");
It will give you your current project path like:
C:\Users\narendra.h.rajput\Automation\projectName
Now append your image path in your project path
<parameter name="adverImage" value="/res/sale_sign.jpg"/>
In Code
private void selectImage(String image)
{
String location= System.getProperty("user.dir");
imageSelect.clear();
imageSelect.sendKeys(location+image);
}
The thing is same as you are giving the absolute path. Because if you see your res/image location in your pc it will be same as above method return
Upvotes: 2