I want to verify if the image name contains certain text or not. Whats the best way to do it
I have attached an image for reference as below:
I want to verify if the image name contains certain text or not. Whats the best way to do it
I have attached an image for reference as below:
One way you could do this (using js) is with the .indexOf
method. In your case, you could use code like this:
// If you gave your img element an id="picture",
// you could get your src text with this line:
var imageSource = document.getElementById("picture").src;
// boolean for whether or not 5.0 exists in the source
var exists = false;
// indexOf will return the index that 5.0 is located at
// if it does not exist, it will return -1
// here, I evaluate if the index of 5.0 is not -1
// if it is not -1, that means it does exist
if (imageSource.indexOf("5.0") != -1)
exists = true;
Here is the w3schools link for the .indexOf
method:
https://www.w3schools.com/jsref/jsref_indexof.asp
Yes, this is JavaScript. Which you CAN use: Execute JavaScript using Selenium WebDriver in C#
Hope this helps, good luck!